Friday, May 31, 2019

state_operations while adding 2 fields

Hi all,

is it posible to bundle 2 AddField migrations with one RunPython?
How should I arrange the state_operations in this case?

The following migration does not work.

Please advice,
Axel

def forwards_func(apps, schema_editor):
with connections['erdb_migration'].cursor() as cursor:
cursor.execute('Alter TABLE account \
ADD column is_account_admin boolean \
DEFAULT false')
cursor.execute('Alter TABLE account \
ADD column self_admin_only boolean \
DEFAULT false')

def reverse_func(apps, schema_editor):
with connections['erdb_migration'].cursor() as cursor:
cursor.execute('Alter TABLE account \
DROP column is_account_admin')
cursor.execute('Alter TABLE account \
DROP column self_admin_only')


class Migration(migrations.Migration):

dependencies = [
('erdb', '0007_add_customer_group'),
]


operations = [
migrations.RunPython(forwards_func, reverse_code=reverse_func),
]

state_operations=[(
migrations.AddField(
model_name='account',
name='is_account_admin',
field=models.BooleanField(
db_column='is_account_admin',
default=False),
),
migrations.RemoveField(
model_name='account',
name='is_account_admin'
)),(
migrations.AddField(
model_name='account',
name='self_admin_only',
field=models.BooleanField(
db_column='self_admin_only',
default=False),
),
migrations.RemoveField(
model_name='account',
name='self_admin_only'
))

],

---
PGP-Key:29E99DD6 ☀ computing @ chaos claudius

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/C379B063-80E2-47ED-BBB0-7E90077E2500%40Chaos1.DE.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment