Django migrations with multiple databases

You have to run migrate once for each database, specifying the target with –database. Each time it will consult your router to see which migrations to actually perform on that database. I’m guessing it was designed this way to favor explicitness over implicitness. For example, your workflow might require you to migrate the different databases … Read more

Django: Best way to merge migrations conflicts

From the Django docs: Because migrations are stored in version control, you’ll occasionally come across situations where you and another developer have both committed a migration to the same app at the same time, resulting in two migrations with the same number. Don’t worry – the numbers are just there for developers’ reference, Django just … Read more

Migrating ManyToManyField to null true, blank true, isn’t recognized

That behavior is correct: null doesn’t mean anything at the database level when used with a ManyToManyField. The declaration of a ManyToManyField causes the creation of an intermediate table to hold the relationship, and although Django will create a standard attribute on your model instance for your convenience, there is no actual column representing it … Read more

–fake-initial vs –fake in Django migration?

Well the documentation is very clear about this –fake-initial Allows Django to skip an app’s initial migration if all database tables with the names of all models created by all CreateModel operations in that migration already exist. This option is intended for use when first running migrations against a database that preexisted the use of … Read more

Revert Django 1.7 RemoveField migration

You can manually edit your migration and add AlterField with default value for a field just before RemoveField. It should be safe even after applying migration. That will make RemoveField that will happen after to be reversible. An example. Having field in model summary named profit that was defined before removal like that: profit = … Read more

How to recreate a deleted table with Django Migrations?

In django 1.7 you can try: 1. Delete your migrations folder 2. In the database: DELETE FROM django_migrations WHERE app = ‘app_name’. You could alternatively just truncate this table. 3. python manage.py makemigrations 4. python manage.py migrate –fake If you are working in django 1.9.5 this is the 100 % solution for this problem: 1. … Read more

How can I skip a migration with Django migrate command?

You can use the –fake option. Once you revert to 0001 you can run python manage.py migrate <app> 0002 –fake and then run python manage.py migrate <app> #Optionally specify 0003 explicitly which would apply only 0003 in this case. If you do not want to follow this process for all the environment/other developers, you can … Read more

Why does django 1.7 creates migrations for changes in field choices?

After raised the ticket and got closed due to duplication, finally found the answer: This is by design. There are several reasons, not least of which for me that datamigrations at points in history need to have a full accurate representation of the models, including all their options not just those which affect the database. … Read more

Received “ValueError: Found wrong number (0) of constraints for …” during Django migration

(Postgres and MySQL Answer) If you look at your actual table (use \d table_name) and look at the indexes, you’ll find an entry for your unique constraint. This is what Django is trying to find and drop. But it can’t find an exact match. For example, “table_name_…6cf2a9c6e98cbd0d_uniq” UNIQUE CONSTRAINT, btree (d, a, b, c) In … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)