我正在使用flask-migrate,SQLAlchemy和Alembic来管理我的数据库。我想在数据库中创建一个新表。新表具有使用现有Enum
的列。我读过许多关于SO的问题,您可以使用带有Enum
标志的现有create_type=False
。这似乎对我不起作用。请参见下面我的修订文件中的upgrade()
函数。
def upgrade():
op.create_table(
'label',sa.Column('id',UUID(as_uuid=True),default=uuid4),sa.Column('labelText',sa.Text,nullable=False),sa.Column('sourceCountry',sa.Enum('it','gb','gr','bg','pt',name='country',create_type=False),nullable=True),sa.PrimaryKeyConstraint('id'),sa.UniqueConstraint('id')
)
op.add_column('entity',sa.Column('labelId',UUID(as_uuid=True)))
op.create_foreign_key(
'fk_entity_label','entity','label',['labelId'],['id'],)
这是我的版本:
flask==1.1.1
flask-Ext==0.1
flask-Migrate==2.5.3
flask-script==2.0.6
flask-SQLAlchemy==2.4.1
alembic==1.4.1
我的错误:
sqlalchemy.exc.ProgrammingError: (psycopg2.errors.DuplicateObject) type "country" already exists
[SQL: CREATE TYPE country AS ENUM ('it','pt')]
(Background on this error at: http://sqlalche.me/e/f405)