This is from django\'s documentation:
Field.unique
If True, this field must be unique throughout the table.
This is enforced at the databas
Running sql scripts directly on the db can be avoided. Rather add the sql execution in your migration:
from __future__ import unicode_literals
from django.db import migrations, connection
def alter_table(apps, schema_editor):
query ="ALTER TABLE ADD UNIQUE (unique_col);"
cursor = connection.cursor()
cursor.execute(query)
cursor.close()
class Migration(migrations.Migration):
dependencies = [
('app', 'yourlastmigration'),
]
operations = [
migrations.RunPython(alter_table),
]