python - Error creating table with foreign key constraint using SQLAlchemy-Migrate -
i'm building app in python. i'm using sqlalchemy-migrate track database schema. have table, user_category, has 2 columns: id , name. i'm trying create user table foreign key user_category table. change script creating user table follows:
from sqlalchemy import * migrate import * migrate.changeset import * meta = metadata() user_category = table('user_category', meta) user = table('user', meta, column('id', integer, primary_key=true), column('email', string(255)), column('first_name', string(40)), column('surname', string(40)), column('password', string(255)), column('user_category', integer, foreignkey("user_category.id")), ) def upgrade(migrate_engine): # upgrade operations go here. don't create own engine; bind migrate_engine # metadata meta.bind = migrate_engine user.create() def downgrade(migrate_engine): # operations reverse above upgrade go here. meta.bind = migrate_engine user.drop()
when run 'manage.py test' , error:
sqlalchemy.exc.noreferencedcolumnerror: not create foreignkey 'user_catego ry.id' on table 'user': table 'user_category' has no column named 'id'
you claim "user_category" table has name , id. definition of "user_category" contains no columns @ :)
Comments
Post a Comment