Today I solved a similar problem - I need to migrate to create a new model, but only for postgres DB, and I found this question. However, Matthew's answer did not help me. In fact, I'm not sure if it works at all. This is because the line with migrations.RunSQL(...) does not actually run SQL; it creates a new object of type RunSQL , which is Command , and then immediately discards it.
This is how I decided to solve the problem if someone tries to find "conditional django migration" in the future:
from __future__ import unicode_literals import django.contrib.postgres.fields from django.db import migrations, models class PostgresOnlyCreateModel(migrations.CreateModel): def database_forwards(self, app_label, schema_editor, from_state, to_state): if schema_editor.connection.vendor.startswith("postgres"): super(PostgresOnlyCreateModel, self).database_forwards(app_label, schema_editor, from_state, to_state) def database_backwards(self, app_label, schema_editor, from_state, to_state): if schema_editor.connection.vendor.startswith("postgres"): super(PostgresOnlyCreateModel, self).database_backwards(app_label, schema_editor, from_state, to_state) class Migration(migrations.Migration): dependencies = [ ...whatever... ] operations = [ PostgresOnlyCreateModel( name='...whatever...', fields=[...whatever...], ), ]
Shaggy frog
source share