Doesn't create ForeignKey for inherited models

Bug #1638349 reported by simulyant
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
sqlalchemy-migrate
New
Undecided
Unassigned

Bug Description

I use Flask-SQLAlchemy. If models A, B inherited from model C by ForeignKey. Then migrate creates ForeignKey only for first model (A or B) and not creates ForeignKey for another model. It should create ForeignKeys for both models A and B. These are some snippets of my code:

`class Party(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
...

class PartyNonAdmin(Party):
id = db.Column(db.Integer, db.ForeignKey('party.id'), primary_key=True)
...

class PartyNonAdmin2(Party):
id = db.Column(db.Integer, db.ForeignKey('party.id'), primary_key=True)
...
`
So classes PartyNonAdmin and PartyNonAdmin2 inherited from Party by ForeignKey. But when I launch db_migrate.py the ForeignKey created only for PartyNonAdmin table (the first of two tables PartyNonAdmin and PartyNonAdmin2).

I use the following db_migrate.py script:
`#!flask/bin/python
import imp
from migrate.versioning import api
from app import db
from config import SQLALCHEMY_DATABASE_URI
from config import SQLALCHEMY_MIGRATE_REPO

migration = SQLALCHEMY_MIGRATE_REPO + '/versions/%03d_migration.py' % (
api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO) + 1)
tmp_module = imp.new_module('model')
old_model = api.create_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
exec old_model in tmp_module.dict
script = api.make_update_script_for_model(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO, tmp_module.meta,
db.metadata)
open(migration, "wt").write(script)
api.upgrade(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO)
print 'New migration saved as ' + migration
print 'Current database version: ' + str(api.db_version(SQLALCHEMY_DATABASE_URI, SQLALCHEMY_MIGRATE_REPO))`

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.