We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Handle invalid data while change data types during migrations
**Related error:**

```
sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) column "pdf_url" contains null values
[SQL: 'ALTER TABLE ticket_holders ADD COLUMN pdf_url VARCHAR NOT NULL']
```

Due to this, migration are not running on `api.eventyay.com`.

Ensure existing data (valid or not) is handled properly and also ensure columns have proper null setting. (for example here, make pdf_url nullable.)
Similarly check and ensure other columns as well


**Full log attached for reference:**

```
2017-06-28T05:49:05.921467228Z     run_migrations_online()
2017-06-28T05:49:05.921470119Z   File "migrations/env.py", line 151, in run_migrations_online
2017-06-28T05:49:05.921473075Z     context.run_migrations()
2017-06-28T05:49:05.921475912Z   File "<string>", line 8, in run_migrations
2017-06-28T05:49:05.921479088Z   File "/usr/local/lib/python2.7/site-packages/alembic/runtime/environment.py", line 817, in run_migrations
2017-06-28T05:49:05.922610188Z     self.get_context().run_migrations(**kw)
2017-06-28T05:49:05.922642643Z   File "/usr/local/lib/python2.7/site-packages/alembic/runtime/migration.py", line 329, in run_migrations
2017-06-28T05:49:05.923243091Z     step.migration_fn(**kw)
2017-06-28T05:49:05.923274018Z   File "/opev/open_event/migrations/versions/c6b183975be9_.py", line 20, in upgrade
2017-06-28T05:49:05.923338965Z     op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=False))
2017-06-28T05:49:05.923364414Z   File "<string>", line 8, in add_column
2017-06-28T05:49:05.923427981Z   File "<string>", line 3, in add_column
2017-06-28T05:49:05.923478561Z   File "/usr/local/lib/python2.7/site-packages/alembic/operations/ops.py", line 1551, in add_column
2017-06-28T05:49:05.926653441Z     return operations.invoke(op)
2017-06-28T05:49:05.926712969Z   File "/usr/local/lib/python2.7/site-packages/alembic/operations/base.py", line 318, in invoke
2017-06-28T05:49:05.927353504Z     return fn(self, operation)
2017-06-28T05:49:05.927386093Z   File "/usr/local/lib/python2.7/site-packages/alembic/operations/toimpl.py", line 123, in add_column
2017-06-28T05:49:05.927969743Z     schema=schema
2017-06-28T05:49:05.927998827Z   File "/usr/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 172, in add_column
2017-06-28T05:49:05.92861825Z     self._exec(base.AddColumn(table_name, column, schema=schema))
2017-06-28T05:49:05.92864919Z   File "/usr/local/lib/python2.7/site-packages/alembic/ddl/impl.py", line 118, in _exec
2017-06-28T05:49:05.928742734Z     return conn.execute(construct, *multiparams, **params)
2017-06-28T05:49:05.928786028Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 945, in execute
2017-06-28T05:49:05.929323557Z     return meth(self, multiparams, params)
2017-06-28T05:49:05.929333376Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py", line 68, in _execute_on_connection
2017-06-28T05:49:05.929336744Z     return connection._execute_ddl(self, multiparams, params)
2017-06-28T05:49:05.929339861Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1002, in _execute_ddl
2017-06-28T05:49:05.929512493Z     compiled
2017-06-28T05:49:05.929538983Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1189, in _execute_context
2017-06-28T05:49:05.929768208Z     context)
2017-06-28T05:49:05.929810133Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
2017-06-28T05:49:05.930067186Z     exc_info
2017-06-28T05:49:05.930093798Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py", line 203, in raise_from_cause
2017-06-28T05:49:05.930194023Z     reraise(type(exception), exception, tb=exc_tb, cause=cause)
2017-06-28T05:49:05.930237111Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1182, in _execute_context
2017-06-28T05:49:05.931176835Z     context)
2017-06-28T05:49:05.931187737Z   File "/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py", line 470, in do_execute
2017-06-28T05:49:05.931191369Z     cursor.execute(statement, parameters)
2017-06-28T05:49:05.931334485Z sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) column "pdf_url" contains null values
2017-06-28T05:49:05.931342263Z  [SQL: 'ALTER TABLE ticket_holders ADD COLUMN pdf_url VARCHAR NOT NULL']
```



--- 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/c6b183975be9_.py`
Content:
```
1 """empty message
2 
3 Revision ID: c6b183975be9
4 Revises: ccd80550c01f
5 Create Date: 2017-06-12 00:42:29.329727
6 
7 """
8 
9 # revision identifiers, used by Alembic.
10 revision = 'c6b183975be9'
11 down_revision = 'ccd80550c01f'
12 
13 from alembic import op
14 import sqlalchemy as sa
15 import sqlalchemy_utils
16 
17 
18 def upgrade():
19     # ### commands auto generated by Alembic - please adjust! ###
20     op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=False))
21     # ### end Alembic commands ###
22 
23 
24 def downgrade():
25     # ### commands auto generated by Alembic - please adjust! ###
26     op.drop_column('ticket_holders', 'pdf_url')
27     # ### end Alembic commands ###
28
```
--- 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()

```

diff --git a/migrations/versions/c6b183975be9_.py b/migrations/versions/c6b183975be9_.py
--- a/migrations/versions/c6b183975be9_.py
+++ b/migrations/versions/c6b183975be9_.py
@@ -17,7 +17,7 @@
 
 def upgrade():
     # ### commands auto generated by Alembic - please adjust! ###
-    op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=False))
+    op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=True))
     # ### end Alembic commands ###

{"golden_diff": "diff --git a/migrations/versions/c6b183975be9_.py b/migrations/versions/c6b183975be9_.py\n--- a/migrations/versions/c6b183975be9_.py\n+++ b/migrations/versions/c6b183975be9_.py\n@@ -17,7 +17,7 @@\n \n def upgrade():\n     # ### commands auto generated by Alembic - please adjust! ###\n-    op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=False))\n+    op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=True))\n     # ### end Alembic commands ###\n", "issue": "Handle invalid data while change data types during migrations\n**Related error:**\r\n\r\n```\r\nsqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) column \"pdf_url\" contains null values\r\n[SQL: 'ALTER TABLE ticket_holders ADD COLUMN pdf_url VARCHAR NOT NULL']\r\n```\r\n\r\nDue to this, migration are not running on `api.eventyay.com`.\r\n\r\nEnsure existing data (valid or not) is handled properly and also ensure columns have proper null setting. (for example here, make pdf_url nullable.)\r\nSimilarly check and ensure other columns as well\r\n\r\n\r\n**Full log attached for reference:**\r\n\r\n```\r\n2017-06-28T05:49:05.921467228Z     run_migrations_online()\r\n2017-06-28T05:49:05.921470119Z   File \"migrations/env.py\", line 151, in run_migrations_online\r\n2017-06-28T05:49:05.921473075Z     context.run_migrations()\r\n2017-06-28T05:49:05.921475912Z   File \"<string>\", line 8, in run_migrations\r\n2017-06-28T05:49:05.921479088Z   File \"/usr/local/lib/python2.7/site-packages/alembic/runtime/environment.py\", line 817, in run_migrations\r\n2017-06-28T05:49:05.922610188Z     self.get_context().run_migrations(**kw)\r\n2017-06-28T05:49:05.922642643Z   File \"/usr/local/lib/python2.7/site-packages/alembic/runtime/migration.py\", line 329, in run_migrations\r\n2017-06-28T05:49:05.923243091Z     step.migration_fn(**kw)\r\n2017-06-28T05:49:05.923274018Z   File \"/opev/open_event/migrations/versions/c6b183975be9_.py\", line 20, in upgrade\r\n2017-06-28T05:49:05.923338965Z     op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=False))\r\n2017-06-28T05:49:05.923364414Z   File \"<string>\", line 8, in add_column\r\n2017-06-28T05:49:05.923427981Z   File \"<string>\", line 3, in add_column\r\n2017-06-28T05:49:05.923478561Z   File \"/usr/local/lib/python2.7/site-packages/alembic/operations/ops.py\", line 1551, in add_column\r\n2017-06-28T05:49:05.926653441Z     return operations.invoke(op)\r\n2017-06-28T05:49:05.926712969Z   File \"/usr/local/lib/python2.7/site-packages/alembic/operations/base.py\", line 318, in invoke\r\n2017-06-28T05:49:05.927353504Z     return fn(self, operation)\r\n2017-06-28T05:49:05.927386093Z   File \"/usr/local/lib/python2.7/site-packages/alembic/operations/toimpl.py\", line 123, in add_column\r\n2017-06-28T05:49:05.927969743Z     schema=schema\r\n2017-06-28T05:49:05.927998827Z   File \"/usr/local/lib/python2.7/site-packages/alembic/ddl/impl.py\", line 172, in add_column\r\n2017-06-28T05:49:05.92861825Z     self._exec(base.AddColumn(table_name, column, schema=schema))\r\n2017-06-28T05:49:05.92864919Z   File \"/usr/local/lib/python2.7/site-packages/alembic/ddl/impl.py\", line 118, in _exec\r\n2017-06-28T05:49:05.928742734Z     return conn.execute(construct, *multiparams, **params)\r\n2017-06-28T05:49:05.928786028Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 945, in execute\r\n2017-06-28T05:49:05.929323557Z     return meth(self, multiparams, params)\r\n2017-06-28T05:49:05.929333376Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/sql/ddl.py\", line 68, in _execute_on_connection\r\n2017-06-28T05:49:05.929336744Z     return connection._execute_ddl(self, multiparams, params)\r\n2017-06-28T05:49:05.929339861Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 1002, in _execute_ddl\r\n2017-06-28T05:49:05.929512493Z     compiled\r\n2017-06-28T05:49:05.929538983Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 1189, in _execute_context\r\n2017-06-28T05:49:05.929768208Z     context)\r\n2017-06-28T05:49:05.929810133Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 1402, in _handle_dbapi_exception\r\n2017-06-28T05:49:05.930067186Z     exc_info\r\n2017-06-28T05:49:05.930093798Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/util/compat.py\", line 203, in raise_from_cause\r\n2017-06-28T05:49:05.930194023Z     reraise(type(exception), exception, tb=exc_tb, cause=cause)\r\n2017-06-28T05:49:05.930237111Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/base.py\", line 1182, in _execute_context\r\n2017-06-28T05:49:05.931176835Z     context)\r\n2017-06-28T05:49:05.931187737Z   File \"/usr/local/lib/python2.7/site-packages/sqlalchemy/engine/default.py\", line 470, in do_execute\r\n2017-06-28T05:49:05.931191369Z     cursor.execute(statement, parameters)\r\n2017-06-28T05:49:05.931334485Z sqlalchemy.exc.IntegrityError: (psycopg2.IntegrityError) column \"pdf_url\" contains null values\r\n2017-06-28T05:49:05.931342263Z  [SQL: 'ALTER TABLE ticket_holders ADD COLUMN pdf_url VARCHAR NOT NULL']\r\n```\r\n\r\n\n", "before_files": [{"content": "\"\"\"empty message\n\nRevision ID: c6b183975be9\nRevises: ccd80550c01f\nCreate Date: 2017-06-12 00:42:29.329727\n\n\"\"\"\n\n# revision identifiers, used by Alembic.\nrevision = 'c6b183975be9'\ndown_revision = 'ccd80550c01f'\n\nfrom alembic import op\nimport sqlalchemy as sa\nimport sqlalchemy_utils\n\n\ndef upgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=False))\n    # ### end Alembic commands ###\n\n\ndef downgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.drop_column('ticket_holders', 'pdf_url')\n    # ### end Alembic commands ###\n", "path": "migrations/versions/c6b183975be9_.py"}], "after_files": [{"content": "\"\"\"empty message\n\nRevision ID: c6b183975be9\nRevises: ccd80550c01f\nCreate Date: 2017-06-12 00:42:29.329727\n\n\"\"\"\n\n# revision identifiers, used by Alembic.\nrevision = 'c6b183975be9'\ndown_revision = 'ccd80550c01f'\n\nfrom alembic import op\nimport sqlalchemy as sa\nimport sqlalchemy_utils\n\n\ndef upgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.add_column('ticket_holders', sa.Column('pdf_url', sa.String(), nullable=True))\n    # ### end Alembic commands ###\n\n\ndef downgrade():\n    # ### commands auto generated by Alembic - please adjust! ###\n    op.drop_column('ticket_holders', 'pdf_url')\n    # ### end Alembic commands ###\n", "path": "migrations/versions/c6b183975be9_.py"}]}