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
0
votes
0 answers

Django Many to Many migration can't insert null into id

I'm trying to migrate a column from a Char field to a Many-to-Many field running Django 1.8.2. I'm doing a custom Data Migration, to move the data properly. When I try to migrate, I get a database error, can't insert null into the many to many table…
Shawn
  • 717
  • 11
  • 31
0
votes
1 answer

Problems accessing Django model fields from model before migration

I'm moving the field some_field from Model_A to a new Model_B, with a OneToOne relationship. Before deleting this field in Model_A, I want to copy the value from (the historical) Model_A to the newly created Model_B. The problem is that I cannot…
Karlis Rode
  • 3,643
  • 2
  • 16
  • 16
0
votes
2 answers

Django migrations - how to make it forget?

I've been sketching out a new Django app with the runserver dev server running in a background window to tracking network wiring, and briefly had this in my model: class Interface(models.Model): name = models.CharField(max_length=200) #…
AnotherHowie
  • 818
  • 1
  • 11
  • 28
0
votes
1 answer

django-admin migrate can't find module

I'm following Amazon guide on deploying a Django app to elastic beanstalk, but I get an error that I could reproduce locally. All the commands were ran locally. I created a virtualenv with python 3.4, activated it, installed Django and started a…
ibrabeicker
  • 1,786
  • 2
  • 19
  • 31
0
votes
2 answers

Why Django makemigrations detect changes everytime it is run due to accent in help_text/verbose_name attributes?

I'm working with Python-2.7 and got a models.py file with French strings (i.e. accented) in help_text or verbose_name attributes. models.py Complete models.py is available as a gist. Here is an excerpt: # -*- coding: utf-8 -*- class…
0
votes
0 answers

Django 1.8.4 makemigrations CreateModel changes field's order

We've just switched to Django 1.8.4 (from 1.6, so first time using migrations), and we've noticed an issue when using the makemigrations command. The issue happens when creating a new model that contains Foreign Keys. The command generates a…
fougerejo
  • 51
  • 1
  • 6
0
votes
1 answer

Load fixture in django migrations using loaddata

My django application needs data to work properly, so in certain migration I loaded data using the recommended method by almost all stack overflow answers: from django.core.management import call_command def load_fixture(apps,…
Marco Lavagnino
  • 1,140
  • 12
  • 31
0
votes
1 answer

Django runserver and makemigration fail with trace showing older migration

I added a field to a model this evening and when I ran makemigrations it told me the field didn't exist. I noticed a previous migration was referenced in the trace. I tried adding another field to a different model and makemigrations worked…
wilbbe01
  • 1,931
  • 1
  • 24
  • 38
0
votes
1 answer

Django migration fails when removing ManyToManyField

In a live web app, I have the following models (abridged): class Ad(models.Model): name = models.CharField(max_length=50) apps = models.ManyToManyField(App, null=True, blank=True) class App(models.Model): name =…
bfox
  • 274
  • 2
  • 13
0
votes
2 answers

django: by mistake deleted migration files from production server

By mistake I deleted all the migration files from all apps on production server. Now running python manage.py makemigrations and then python manage.py migrate raises: "field already exists in the database" error for each field, What should I do…
Kunal Kumar
  • 67
  • 3
  • 6
0
votes
2 answers

Run migrations without loading initial_data.json

I provide a lista of users for my application in a json located in my app: myapp/ fixtures/ initial_data.json it load everytime I run python manage.py migrate. I've read the Providing initial data for models document, but it does not mention…
Gocht
  • 9,924
  • 3
  • 42
  • 81
0
votes
1 answer

Django South Migration Inconsistency

I currently have an issue with some south migrations in my django application. After doing a code merge I have come across a couple migrations with the same index. I have successfully reversed the migrations back to right before the first…
dnaluz
  • 135
  • 1
  • 10
0
votes
1 answer

How to migrate an existing Django project to a new and empty database (or schema)?

I have been working on a Django (version 1.7.6) project for various months. Throughout this time each application evolved a good deal and there now various dozens of migrations. I would like to deploy this project into a new development…
Luís de Sousa
  • 5,765
  • 11
  • 49
  • 86
0
votes
1 answer

Upgrading from Django1.3 to 1.8 - Are migrations mandatory?

My application has been on production for 3 years and the DB model is stable. It seems to me that adding migrations support is more pain that it is worth. Is it possible/desirable to upgrade without migrations support?
ferchor2003
  • 103
  • 9
0
votes
2 answers

Using south dependent apps with django 1.7 new migration system

I want to use django-taggit but the docs said it's dependent on south. The django docs are saying that south(with improvements etc.) has been integrated into django 1.7. Does i con simply used south dependent apps like taggit with new migration…
Lord_JABA
  • 2,545
  • 7
  • 31
  • 58