Sandor A Sandor A - 18 days ago 8
MySQL Question

Django Migrations Partially Complete

I am using Django 1.9.7 and MySQL.

I have a migration file with multiple operations.

migrations.RemoveField(
model_name='team',
name='country',
),
migrations.AddField(
model_name='team',
name='description',
field=models.CharField(blank=True, max_length=200, null=True),
),
migrations.AlterField(
model_name='team',
name='iso_country',
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

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.