JoseBazBaz
JoseBazBaz

Reputation: 1445

ORM model change causes errors like "column … does not exist"

Have been trying to figure this out for an hour - and still have no idea what the problem is.

The following code is causing the error:

team = Team.query.filter_by(name=request.form['newTeamName']).first()

More details on the error:

ProgrammingError: (ProgrammingError) column team.user_id does not exist

What should I do to fix this bug?

Upvotes: 5

Views: 14451

Answers (1)

Michael Merickel
Michael Merickel

Reputation: 23341

It sounds like you've modified the model without updating the database. You need to do this via a migration of some sort. For things like adding new tables you can simply run metadata.create_all(bind=engine). However for fine-grained changes like adding columns, etc, you need to alter the table yourself or use a system like alembic. Of course if this is just during development you should probably just blow away the database and recreate it with the new definitions.

Upvotes: 6

Related Questions