强文本我的先前型号:
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 ,我仍然只会收到上述错误。 要解决此错误需要做些什么?