使用ALEMBIC更改SQLalchemy模型中主键的列类型会生成NULL错误

强文本我的先前型号:

class sample(Base):
    __tablename__ = "sample"
    id = Column(Integer,primary_key=True,index=True)
    name = Column(String(30),unique=True)

我的最新型号:

class sample(Base):
    __tablename__ = "sample"

    id = Column(String(length=1000),unique=True)

id的迁移数据字段:

op.alter_column('sample','id',existing_type=mysql.BIGINT(display_width=20),type_=sa.String(length=1000))

我在升级head时遇到以下错误:

sqlalchemy.exc.DataError: (MySQLdb._exceptions.DataError) (1171,'All parts of a PRIMARY KEY must be NOT NULL; if you need NULL in a key,use UNIQUE instead')
[SQL: ALTER TABLE sample MODIFY id VARCHAR(1000) NULL]

即使我为id字段指定 nullable = False ,我仍然只会收到上述错误。 要解决此错误需要做些什么?

jasonlevon 回答:使用ALEMBIC更改SQLalchemy模型中主键的列类型会生成NULL错误

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2578197.html

大家都在问