mirror of
https://github.com/bookwyrm-social/bookwyrm.git
synced 2024-11-27 20:11:14 +00:00
Merge pull request #557 from cincodenada/fix-email-migration
Fix migration for if db has multiple empty emails
This commit is contained in:
commit
3a303448bc
1 changed files with 15 additions and 0 deletions
|
@ -2,6 +2,15 @@
|
|||
|
||||
from django.db import migrations, models
|
||||
|
||||
def empty_to_null(apps, schema_editor):
|
||||
User = apps.get_model("bookwyrm", "User")
|
||||
db_alias = schema_editor.connection.alias
|
||||
User.objects.using(db_alias).filter(email="").update(email=None)
|
||||
|
||||
def null_to_empty(apps, schema_editor):
|
||||
User = apps.get_model("bookwyrm", "User")
|
||||
db_alias = schema_editor.connection.alias
|
||||
User.objects.using(db_alias).filter(email=None).update(email="")
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
|
@ -14,6 +23,12 @@ class Migration(migrations.Migration):
|
|||
name='shelfbook',
|
||||
options={'ordering': ('-created_date',)},
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='email',
|
||||
field=models.EmailField(max_length=254, null=True),
|
||||
),
|
||||
migrations.RunPython(empty_to_null, null_to_empty),
|
||||
migrations.AlterField(
|
||||
model_name='user',
|
||||
name='email',
|
||||
|
|
Loading…
Reference in a new issue