prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  import will crash ctfd
  <!--
  If this is a bug report please fill out the template below.
  
  If this is a feature request please describe the behavior that you'd like to see.
  -->
  
  **Environment**:
  
    - CTFd Version/Commit: 2.1.3
    - Operating System: ubuntu 18.04
    - Web Browser and Version: Opera 60.0.3255.170
  
  **What happened?**
  trying to import db (zip file)
  **What did you expect to happen?**
  it would import db (zip file)
  **How to reproduce your issue**
  
  **Any associated stack traces or error logs**
  Failed to disable foreign key checks. Continuing.
  Error: No support for ALTER of constraints in SQLite dialect
  
  I believe it's Alembic fault  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `migrations/versions/b5551cd26764_add_captain_column_to_teams.py`
  Content:
  ```
  1 """Add captain column to Teams
  2 
  3 Revision ID: b5551cd26764
  4 Revises: 4e4d5a9ea000
  5 Create Date: 2019-04-12 00:29:08.021141
  6 
  7 """
  8 from CTFd.models import db
  9 from alembic import op
  10 import sqlalchemy as sa
  11 from sqlalchemy.sql import text, table, column, and_
  12 
  13 # revision identifiers, used by Alembic.
  14 revision = 'b5551cd26764'
  15 down_revision = '4e4d5a9ea000'
  16 branch_labels = None
  17 depends_on = None
  18 
  19 teams_table = table('teams',
  20     column('id', db.Integer),
  21     column('captain_id', db.Integer),
  22 )
  23 
  24 users_table = table('users',
  25     column('id', db.Integer),
  26     column('team_id', db.Integer),
  27 )
  28 
  29 
  30 def upgrade():
  31     # ### commands auto generated by Alembic - please adjust! ###
  32     op.add_column('teams', sa.Column('captain_id', sa.Integer(), nullable=True))
  33     op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id'])
  34 
  35     connection = op.get_bind()
  36     for team in connection.execute(teams_table.select()):
  37         users = connection.execute(
  38             users_table.select().where(users_table.c.team_id == team.id).order_by(users_table.c.id).limit(1)
  39         )
  40         for user in users:
  41             connection.execute(
  42                 teams_table.update().where(
  43                     teams_table.c.id == team.id
  44                 ).values(
  45                     captain_id=user.id
  46                 )
  47             )
  48     # ### end Alembic commands ###
  49 
  50 
  51 def downgrade():
  52     # ### commands auto generated by Alembic - please adjust! ###
  53     op.drop_constraint('team_captain_id', 'teams', type_='foreignkey')
  54     op.drop_column('teams', 'captain_id')
  55     # ### end Alembic commands ###
  56
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/migrations/versions/b5551cd26764_add_captain_column_to_teams.py b/migrations/versions/b5551cd26764_add_captain_column_to_teams.py
  --- a/migrations/versions/b5551cd26764_add_captain_column_to_teams.py
  +++ b/migrations/versions/b5551cd26764_add_captain_column_to_teams.py
  @@ -30,7 +30,11 @@
   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()):
  
verification_info: {"golden_diff": "diff --git a/migrations/versions/b5551cd26764_add_captain_column_to_teams.py b/migrations/versions/b5551cd26764_add_captain_column_to_teams.py\n--- a/migrations/versions/b5551cd26764_add_captain_column_to_teams.py\n+++ b/migrations/versions/b5551cd26764_add_captain_column_to_teams.py\n@@ -30,7 +30,11 @@\n def upgrade():\n     # ### commands auto generated by Alembic - please adjust! ###\n     op.add_column('teams', sa.Column('captain_id', sa.Integer(), nullable=True))\n-    op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id'])\n+\n+    bind = op.get_bind()\n+    url = str(bind.engine.url)\n+    if url.startswith('sqlite') is False:\n+        op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id'])\n \n     connection = op.get_bind()\n     for team in connection.execute(teams_table.select()):\n", "issue": "import will crash ctfd\n<!--\r\nIf this is a bug report please fill out the template below.\r\n\r\nIf this is a feature request please describe the behavior that you'd like to see.\r\n-->\r\n\r\n**Environment**:\r\n\r\n  - CTFd Version/Commit: 2.1.3\r\n  - Operating System: ubuntu 18.04\r\n  - Web Browser and Version: Opera 60.0.3255.170\r\n\r\n**What happened?**\r\ntrying to import db (zip file)\r\n**What did you expect to happen?**\r\nit would import db (zip file)\r\n**How to reproduce your issue**\r\n\r\n**Any associated stack traces or error logs**\r\nFailed to disable foreign key checks. Continuing.\r\nError: No support for ALTER of constraints in SQLite dialect\r\n\r\nI believe it's Alembic fault  \n", "before_files": [{"content": "\"\"\"Add captain column to Teams\n\nRevision ID: b5551cd26764\nRevises: 4e4d5a9ea000\nCreate Date: 2019-04-12 00:29:08.021141\n\n\"\"\"\nfrom CTFd.models import db\nfrom alembic import op\nimport sqlalchemy as sa\nfrom sqlalchemy.sql import text, table, column, and_\n\n# revision identifiers, used by Alembic.\nrevision = 'b5551cd26764'\ndown_revision = '4e4d5a9ea000'\nbranch_labels = None\ndepends_on = None\n\nteams_table = table('teams',\n    column('id', db.Integer),\n    column('captain_id', db.Integer),\n)\n\nusers_table = table('users',\n    column('id', db.Integer),\n    column('team_id', db.Integer),\n)\n\n\ndef upgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.add_column('teams', sa.Column('captain_id', sa.Integer(), nullable=True))\n    op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id'])\n\n    connection = op.get_bind()\n    for team in connection.execute(teams_table.select()):\n        users = connection.execute(\n            users_table.select().where(users_table.c.team_id == team.id).order_by(users_table.c.id).limit(1)\n        )\n        for user in users:\n            connection.execute(\n                teams_table.update().where(\n                    teams_table.c.id == team.id\n                ).values(\n                    captain_id=user.id\n                )\n            )\n    # ### end Alembic commands ###\n\n\ndef downgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.drop_constraint('team_captain_id', 'teams', type_='foreignkey')\n    op.drop_column('teams', 'captain_id')\n    # ### end Alembic commands ###\n", "path": "migrations/versions/b5551cd26764_add_captain_column_to_teams.py"}], "after_files": [{"content": "\"\"\"Add captain column to Teams\n\nRevision ID: b5551cd26764\nRevises: 4e4d5a9ea000\nCreate Date: 2019-04-12 00:29:08.021141\n\n\"\"\"\nfrom CTFd.models import db\nfrom alembic import op\nimport sqlalchemy as sa\nfrom sqlalchemy.sql import text, table, column, and_\n\n# revision identifiers, used by Alembic.\nrevision = 'b5551cd26764'\ndown_revision = '4e4d5a9ea000'\nbranch_labels = None\ndepends_on = None\n\nteams_table = table('teams',\n    column('id', db.Integer),\n    column('captain_id', db.Integer),\n)\n\nusers_table = table('users',\n    column('id', db.Integer),\n    column('team_id', db.Integer),\n)\n\n\ndef upgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.add_column('teams', sa.Column('captain_id', sa.Integer(), nullable=True))\n\n    bind = op.get_bind()\n    url = str(bind.engine.url)\n    if url.startswith('sqlite') is False:\n        op.create_foreign_key('team_captain_id', 'teams', 'users', ['captain_id'], ['id'])\n\n    connection = op.get_bind()\n    for team in connection.execute(teams_table.select()):\n        users = connection.execute(\n            users_table.select().where(users_table.c.team_id == team.id).order_by(users_table.c.id).limit(1)\n        )\n        for user in users:\n            connection.execute(\n                teams_table.update().where(\n                    teams_table.c.id == team.id\n                ).values(\n                    captain_id=user.id\n                )\n            )\n    # ### end Alembic commands ###\n\n\ndef downgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.drop_constraint('team_captain_id', 'teams', type_='foreignkey')\n    op.drop_column('teams', 'captain_id')\n    # ### end Alembic commands ###\n", "path": "migrations/versions/b5551cd26764_add_captain_column_to_teams.py"}]}