Questions tagged [django-migrations]

Django migrations are a way to apply changes to a database previously created, introduced in Django 1.7. This tool is used when a model is modified (adding a field, deleting a model, etc.) and you need to apply these changes to your database.

Migrations are introduced in Django 1.7 to make easier modifications in models:

Migrations are Django’s way of propagating changes you make to your models (adding a field, deleting a model, etc.) into your database schema. They’re designed to be mostly automatic, but you’ll need to know when to make migrations, when to run them, and the common problems you might run into.

There are several commands which you will use to interact with migrations and Django’s handling of database schema:

  • migrate, which is responsible for (un)applying migrations
  • makemigrations, to create new migrations files based on model modifications
  • sqlmigrate, which displays the SQL statements for a migration.
  • showmigrations, which lists a project’s migrations and their status.

This tag is not about migrating to Django from another framework. This is supposed to replace , which is a third-party mainly used until Django 1.6 to migrate models modifications.

1460 questions
7
votes
1 answer

Upgrading from Django 1.6 to 1.9: python manage.py migrate failure

I'm running Django 1.6.6 on production and have recently upgraded to 1.9.7 on staging (dev server). This update was performed on the server and I followed the steps outlined here Upgrading from South. I noticed that the structure of the migration…
Keenan Lawrence
  • 1,446
  • 10
  • 16
7
votes
3 answers

Should i edit the django migration file to edit mismatched dependencies

I have landed into quite a unique problem. I created the model 1.'message', used it for a while, then i changed it to 2. 'messages' and after that again changed it back to 3. 'message' but this time with many changes in the model fields. As i got to…
sprksh
  • 2,204
  • 2
  • 26
  • 43
7
votes
2 answers

expected string or buffer ,date_re.match(value) django error

I want to extent custom user model in django.I copy paste code from django official website. When i want to migrate it it throw error TypeError: expected string or buffer models.py education=models.CharField(max_length=13) from django.db import…
Cp Verma
  • 462
  • 5
  • 19
7
votes
1 answer

Django migration - disable system checks

I upgraded from Django 1.7 to Django 1.9. I have a number of migrations. Since the upgrade I can no longer create a fresh database. The problem is that "django manage.py migrate" runs checks. The checks import the application urls. These ultimately…
Kevin Gill
  • 407
  • 1
  • 5
  • 14
7
votes
7 answers

Django Table already exist

Here is my Django Migration file. When I run python manage.py makemigrations/migrate I get this error. Error:- django.db.utils.OperationalError: (1050, "Table 'tickets_duration' already exists") I have dropped the database and running it…
user1050619
  • 19,822
  • 85
  • 237
  • 413
7
votes
3 answers

GenericForeignKey data migtation error: 'content_object' is an invalid keyword argument

I want to create data migrations for a model(Comment) which has a GenericForeignKey relation. My model was made according to django documentation for contenttypes. Models: ... class NiceMeme(models.Model): """ Example model. """ …
Laraconda
  • 667
  • 6
  • 15
7
votes
3 answers

How to delete django migrations after squashing them?

Django documentation says we could delete migrations after squashing them: You should commit this migration but leave the old ones in place; the new migration will be used for new installs. Once you are sure all instances of the code base have…
mehmet
  • 7,720
  • 5
  • 42
  • 48
7
votes
1 answer

NOT NULL constraint failed when running `migrate`

I changed my models.py file and when running migrate I get this error. The property is a OneToOneField(). I have tried adding null=True but that doesn't seem to fix it. It is also weird that even when I comment out the property and run…
bencunningham
  • 356
  • 1
  • 5
  • 12
7
votes
1 answer

Django 1.7 makemigrations renaming tables to None

I had to move a few models from one app to another, and I followed the instructions on this answer https://stackoverflow.com/a/26472482/188614. Basically I used the CreateModel migrations generated by python manage.py makemigrations, wrapped them…
Diego Ponciano
  • 1,453
  • 1
  • 19
  • 23
7
votes
2 answers

Django 1.7 synchronize unmigrated apps

I started my model: myapp.models.py class MyModel(models.Model): field_a = models.FloatField() field_c = models.FloatField() Then ran ./manage.py migrate on my new project and it was all good: Operations to perform: Synchronize…
Williams
  • 4,044
  • 1
  • 37
  • 53
6
votes
5 answers

CREATE TABLE "django_migrations" ("id" bigint NOT NULL PRIMA

During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/Users/p.gauthamprasad/Downloads/pb/pbapp/manage.py", line 22, in main() File…
6
votes
3 answers

How to organize migration for two related models and automatically set default field value for id of newly created object?

Suppose there is a production database, there is some data in it. I need to migrate in the next tricky case. There is a model (already in db), say Model, it has foreign keys to other models. class ModelA: ... class ModelX: ... class Model:   a =…
Anton Ovsyannikov
  • 1,010
  • 1
  • 12
  • 30
6
votes
1 answer

Django migration with "--fake-initial" is not working if AddField referes to "same" column

I'm playing with django (I'm a quite new beginner) and while surfing the web I read it could be possible to keep our internal camelCase naming conventions inside the mySQL database and also for the models' name inside models.py Well, after some days…
6
votes
1 answer

How to store third party apps migrations in django

I'm fairly new to python and django, and trying to build a simple calendar based on django-scheduler package. According to django-scheduler docs, a custom base class can be used to add additional fields, managers and such. So, I used an abstract…
Dmitry Oleinik
  • 700
  • 1
  • 7
  • 20
6
votes
3 answers

Apply migrations and models from all the apps in Django

I'm using Django and I have an schema like this: mainapp |---mainapp | |---migrations.py | |---models/ |---app2 |---migrations/ |---models/ But, when I execute: python manage.py migrate it is generationg the tables of mainapp/models,…
Benjamin RD
  • 11,516
  • 14
  • 87
  • 157