Model 使用ALEMBIC抛出修改SQLalchemy模型中的字段名;重复列名错误";
我以前的型号:Model 使用ALEMBIC抛出修改SQLalchemy模型中的字段名;重复列名错误";,model,sqlalchemy,database-migration,alembic,sqlalchemy-migrate,Model,Sqlalchemy,Database Migration,Alembic,Sqlalchemy Migrate,我以前的型号: class sample(Base): __tablename__ = "sample" id = Column(BigInteger, primary_key=True,index=True) Name = Column(String(30),index=True) class sample(Base): __tablename__ = "sample" id = Column(BigInteger, primary_key=True,
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
Name = Column(String(30),index=True)
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
name = Column(String(30),index=True)
def upgrade():
op.add_column('sample', sa.Column('name', sa.String(length=1000), nullable=False))
op.drop_column('sample', 'Name')
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1060, "Duplicate column name 'name'")
[SQL: ALTER TABLE sampleADD COLUMN `name` VARCHAR(1000) NOT NULL]
(Background on this error at: http://sqlalche.me/e/e3q8)
我的最新型号:
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
Name = Column(String(30),index=True)
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
name = Column(String(30),index=True)
def upgrade():
op.add_column('sample', sa.Column('name', sa.String(length=1000), nullable=False))
op.drop_column('sample', 'Name')
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1060, "Duplicate column name 'name'")
[SQL: ALTER TABLE sampleADD COLUMN `name` VARCHAR(1000) NOT NULL]
(Background on this error at: http://sqlalche.me/e/e3q8)
我运行了命令alembic revision--autogenerate-m“将名称字段更改为名称”
生成的我的迁移详细信息:
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
Name = Column(String(30),index=True)
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
name = Column(String(30),index=True)
def upgrade():
op.add_column('sample', sa.Column('name', sa.String(length=1000), nullable=False))
op.drop_column('sample', 'Name')
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1060, "Duplicate column name 'name'")
[SQL: ALTER TABLE sampleADD COLUMN `name` VARCHAR(1000) NOT NULL]
(Background on this error at: http://sqlalche.me/e/e3q8)
我在升级磁头(alembic升级磁头)时遇到以下错误:
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
Name = Column(String(30),index=True)
class sample(Base):
__tablename__ = "sample"
id = Column(BigInteger, primary_key=True,index=True)
name = Column(String(30),index=True)
def upgrade():
op.add_column('sample', sa.Column('name', sa.String(length=1000), nullable=False))
op.drop_column('sample', 'Name')
sqlalchemy.exc.OperationalError: (MySQLdb._exceptions.OperationalError) (1060, "Duplicate column name 'name'")
[SQL: ALTER TABLE sampleADD COLUMN `name` VARCHAR(1000) NOT NULL]
(Background on this error at: http://sqlalche.me/e/e3q8)
Alembic正在尝试删除现有列并尝试创建新列,但我想更新特定列。
我如何才能做到这一点???您可能想要:
op.alter\u column('sample','Name',new\u column\u Name='Name'))
您可能需要:
op.alter\u column('sample','Name',new\u column\u Name='Name'))