From 8b3bb92c9dbe3aebad49aa7f45f5b05675a68ef6 Mon Sep 17 00:00:00 2001 From: Kevin Chung Date: Wed, 3 Jul 2019 00:04:50 -0400 Subject: [PATCH] Only add team_captain_id foreign key if the db backend isn't SQLite (#1048) * Only add `teams.team_captain_id` foreign key if the db backend isn't SQLite. SQLite does not support ALTER for the manipulation of columns/constraints. * Closes #1041 --- .../versions/b5551cd26764_add_captain_column_to_teams.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/migrations/versions/b5551cd26764_add_captain_column_to_teams.py b/migrations/versions/b5551cd26764_add_captain_column_to_teams.py index 9279f119..30271326 100644 --- a/migrations/versions/b5551cd26764_add_captain_column_to_teams.py +++ b/migrations/versions/b5551cd26764_add_captain_column_to_teams.py @@ -30,7 +30,11 @@ users_table = table('users', def upgrade(): # ### commands auto generated by Alembic - please adjust! ### op.add_column('teams', sa.Column('captain_id', sa.Integer(), nullable=True)) - op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id']) + + bind = op.get_bind() + url = str(bind.engine.url) + if url.startswith('sqlite') is False: + op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id']) connection = op.get_bind() for team in connection.execute(teams_table.select()):