Reputation: 3378
I am going through the flask-admin tutorial.
As the tutorial explains, when I create an instance of ModelView for my User model by using
admin.add_view(ModelView(User, db.session))
I get an error which is: AttributeError: 'ColumnProperty' object has no attribute 'expression'
and when I create an instance of ModelView for my Account model by using:
admin.add_view(ModelView(Account, db.session))
I get an error: Exception: Model Account does not have primary key.
My User model code is:
class User(db.Model):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(80))
email = db.Column(db.String(160))
password = db.Column(db.String(100))
account_id = db.Column(db.Integer, db.ForeignKey('account.id'))
account = db.relationship('Account', backref=db.backref('user', lazy='dynamic'))
Account model code is:
class Account(db.Model):
id = db.Column(db.Integer, primary_key=True)
password = db.Column(db.String(100))
stack trace when creating User ModelView: http://pastebin.com/gf200CHp
stack trace when creating Account ModelView: http://pastebin.com/NYhGBW1Z
I am using flask-sqlalchemy for creating models. Can someone please suggest how to solve these errors?
Upvotes: 2
Views: 1283
Reputation: 1363
I got the same Model ... does not have primary key
exception, but it went away after I upgraded SQLAlchemy from 0.7.10 to 0.8.2:
sudo pip install SQLAlchemy==0.8.2
-Cheers!
Upvotes: 3