Sandor A Sandor A - 1 year ago 103
MySQL Question

Django Migrations Partially Complete

I am using Django 1.9.7 and MySQL.

I have a migration file with multiple operations.

field=models.CharField(blank=True, max_length=200, null=True),
field=models.ForeignKey(on_delete=django.db.models.deletion.DO_NOTHING, to='sys_models.Country', verbose_name='Country'),

Now I was under the impression, that if one of these statements failed, the entire migration would rollback as part of a larger transaction. Is that correct?

I am not seeing this behaviour, rather, I am seeing that it is possible for some DDL statements to succeed during a migration while another fails. Also, I thought the order would be applied top down, is that correct? I am not necessarily seeing this behaviour in Django migrations.

Answer Source

Django will run migrations inside a transaction for SQLite and PostgreSQL, as these databases that support DDL transactions. However, MySQL does not support DDL transactions.

I assume that the operations run in order, so I'm surprised that you are seeing different behaviour, but I'm not familiar enough with the code to give a definitive answer about that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download