Repository: fossasia/open-event-server

Issue:
IntegrityError: (psycopg2.IntegrityError) column "licence" contains null values
https://sentry.eventyay.com/eventyay/api/issues/20/

```
IntegrityError: (psycopg2.IntegrityError) column "licence" contains null values
 [SQL: 'ALTER TABLE event_copyrights ALTER COLUMN licence SET NOT NULL']
(26 additional frame(s) were not displayed)
...
  File "sqlalchemy/engine/base.py", line 1189, in _execute_context
    context)
  File "sqlalchemy/engine/base.py", line 1402, in _handle_dbapi_exception
    exc_info
  File "sqlalchemy/util/compat.py", line 203, in raise_from_cause
    reraise(type(exception), exception, tb=exc_tb, cause=cause)
  File "sqlalchemy/engine/base.py", line 1182, in _execute_context
    context)
  File "sqlalchemy/engine/default.py", line 470, in do_execute
    cursor.execute(statement, parameters)

IntegrityError: (psycopg2.IntegrityError) column "licence" contains null values
 [SQL: 'ALTER TABLE event_copyrights ALTER COLUMN licence SET NOT NULL']
```

> This error occurred when running the migrations against a copy of the production database


Discussion:

Resolving patch:
diff --git a/migrations/versions/740b89e12cbb_.py b/migrations/versions/740b89e12cbb_.py
--- a/migrations/versions/740b89e12cbb_.py
+++ b/migrations/versions/740b89e12cbb_.py
@@ -18,27 +18,27 @@
 
 def upgrade():
     # commands auto generated by Alembic - please adjust! #
-    op.execute("DELETE FROM event_copyrights WHERE licence='' ",
+    op.execute("DELETE FROM event_copyrights WHERE licence='' or licence IS NULL ",
                execution_options=None)
-    op.execute("DELETE FROM sessions WHERE title='' ",
+    op.execute("DELETE FROM sessions WHERE title='' or title IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM social_links WHERE link='' ",
+    op.execute("DELETE FROM social_links WHERE link='' or link IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM speakers_calls WHERE announcement='' ",
+    op.execute("DELETE FROM speakers_calls WHERE announcement='' or announcement IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM ticket_holders WHERE firstname='' ",
+    op.execute("DELETE FROM ticket_holders WHERE firstname='' or firstname IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM tickets WHERE name='' ",
+    op.execute("DELETE FROM tickets WHERE name='' or name IS NULL",
                execution_options=None)
     op.execute("DELETE FROM tickets WHERE sales_ends_at IS NULL",
                execution_options=None)
     op.execute("DELETE FROM tickets WHERE sales_starts_at IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM tickets WHERE type='' ",
+    op.execute("DELETE FROM tickets WHERE type='' or type IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM users WHERE _email='' ",
+    op.execute("DELETE FROM users WHERE _email='' or _email IS NULL",
                execution_options=None)
-    op.execute("DELETE FROM users WHERE _password='' ",
+    op.execute("DELETE FROM users WHERE _password='' or _password IS NULL",
                execution_options=None)
     op.alter_column('event_copyrights', 'licence',
                     existing_type=sa.VARCHAR(),


Test patch: