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
2 answers

Upgrading to Django1.8 - invalid related_name for field

I am upgrading my app from Django1.7->Django1.8, but I can't make any changes or even run migrations because I keep seeing the following system error whenever I attempt to perform any migration operation in the 1.8…
0
votes
2 answers

DjangoUnicodeDecodeError while makemigrations after upgrading to 1.8

Recently I've upgraded my Django from 1.6.5 to 1.8.3. I have been using South, so, following tutorial, I've removed South, deleted old migrations and run makemigrations. Then I got error: [mefioo@ibmed-server kariera_naukowa]$ env/bin/python…
0
votes
2 answers

django handwritten migrations altering auth

I am using django 1.8.1 and trying to extend the length of auth_user name field from one of my apps. Before, with south, I could just target the app with an underscore like so: db.alter_column('auth_group', 'name', models.CharField(max_length=120,…
Ian Kirkpatrick
  • 1,861
  • 14
  • 33
0
votes
1 answer

Random on model fields generates infinite migration

Here is a class from models.py: class Shop(models.Model): ... code = models.CharField(max_length=4, default=generate_random_code()) As you can imagine, generate_random_code() always return a different string. The problem is, Django…
David Dahan
  • 10,576
  • 11
  • 64
  • 137
0
votes
1 answer

Migrate existing third-party Django model to new customized model

I'm using django-filer for file handling. It has abstract model BaseImage and also there is default model for images called Image which inherits from BaseImage and not abstract. Also, this package allows to specify custom model for images: it hooks…
3ka5_cat
  • 121
  • 1
  • 12
0
votes
0 answers

django 1.7 migrate not updating database

I've run python manage.py makemigrations core which created the following file in /opt/project/core/migrations 0001_initial.py # -*- coding: utf-8 -*- from __future__ import unicode_literals from django.db import models, migrations from django.conf…
whoisearth
  • 4,080
  • 13
  • 62
  • 130
0
votes
1 answer

Django migrations detect the same change many times

I have a model like this: MyModel(models.Model): ... date_start = models.DateTimeField( auto_now=True, editable=True ) date_end = models.DateTimeField( default=datetime.now() + relativedelta(months=3) …
Gocht
  • 9,924
  • 3
  • 42
  • 81
0
votes
1 answer

Custom CMSPlugin migrations in Django 1.7

I'm using Django CMS 3.1 with Django 1.7.8. I'm trying to upgrade an old project to these respective versions but I'm hitting a brick wall with a couple of my custom-written CMSPlugin-inhereting plugins. Django won't migrate any…
Oli
  • 235,628
  • 64
  • 220
  • 299
0
votes
1 answer

django migrations issue NodeNotFoundError

I had to migrate a predefined database so that it works with the django orm. I created the migration files one after another and everything worked as it should. It took 12 migrations. After that I could get a fresh copy of the db and re-apply…
Apostolos
  • 7,763
  • 17
  • 80
  • 150
0
votes
2 answers

Django 1.7 data migration for custom user model

I have created a custom user model for my project. I have written a data migration file to copy contents of auth.User to my new custom user table. It doesn't seem to work properly. It is throwing below error, from django.db import migrations,…
0
votes
1 answer

What is the equivalent of South's "schemamigration --update" for Django>=1.7?

When I was developing with South I was able to use the --update flag for the schemamigration management command to refine the latest migration. This was very convenient for iterative development. Is there an equivalent of the --update flag for…
dukebody
  • 7,025
  • 3
  • 36
  • 61
0
votes
1 answer

Invalid migration SQL when adding blank=True CharField in Django 1.7.8

I'm adding a not null CharField to one of my models: channel_class = models.CharField(max_length=10, blank=True) I create the migration with: django-admin.py makemigrations webapp Which asks me nothing about default values (see this ticket about…
dukebody
  • 7,025
  • 3
  • 36
  • 61
0
votes
0 answers

Unapplying specific Django migrations went awry

I have two apps in my Django project. Foo and Bar. I have made some migrations for Bar and then decided to unapply them. And so I have 6 migrations for Bar and 10 migrations for Foo. ./manage.py migrate Bar 0004 - I'm rolling back to a migration #4.…
Andrey Lukyanov
  • 563
  • 2
  • 7
  • 17
0
votes
1 answer

Queryset in django admin breaks migrations and py.test

I am getting FATAL: database "xxxxxxxxx" does not exist during the loading of py.test. This is coming from the loading of the admin forms, where by I have a queryset being passed to a ModelChoiceField class…
yarbelk
  • 7,215
  • 6
  • 29
  • 37
0
votes
1 answer

Calling loaddata in Django 1.7 migrations is throwing "Unknown column '[field]' in 'field list'"

I'm running into an issue in Django 1.7 when attempting to write multiple migrations in a row. Here's the basic setup of the migrations: Initial schema migration to create the models for an app Data migration that calls loaddata on a specific…
Scott
  • 61
  • 6