Sunday, September 21, 2014

Re: updating site domain with data migration

Hey Anil,

On Sun, Sep 21, 2014 at 05:29:18PM -0700, Anil Jangity wrote:
>$ python manage.py syncdb

Just as a side note: "syncdb" is deprecated and is being replaced by
"migrate".

>
>I have a main/migration/update_site.py:
>def update_site(apps, schema_editor):
> current_site = Site.objects.get_current()
> current_site.domain = "example.com"
> current_site.name = "Example"
> current_site.save()
>
>
>class Migration(migrations.Migration):
>
> operations = [
> migrations.RunPython(update_site),
> ]


You are missing a dependency to the sites app in your migration as well
as to the previous migration in the "main" app. Have a look at
https://docs.djangoproject.com/en/1.7/topics/migrations/#dependencies

Adding

dependencies = [
("main", "whatever_the_name_of_the_previous_migration_is"),
("sites", "0001_initial"),
]

should work.

I tried to explain the way dependencies in Django's new migration
framework work in a blog post:
https://markusholtermann.eu/2014/09/django-17-database-migrations-done-right/#how-do-dependencies-between-migrations-work
Might be interesting.

/Markus

No comments:

Post a Comment