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
1 answer

How to abort Django data migration?

I have a datamigration I actually want to roll back if certain condition happen. I know that migrations are automatically enclosed in a transaction, so I am safe just raising an exception, and then trust all changes to be rolled back. But which…
beruic
  • 5,517
  • 3
  • 35
  • 59
0
votes
2 answers

How to fix migrations for an app with existing schema while not touching other apps?

Django 1.9.7, db.sqlite3 as DB I have a Django project with several apps. For app "A", I had migrations, but I deleted them by accident and pushed to the remote git. Also, a lot of new stuff for other apps was pushed to the git during the day. Other…
srgbnd
  • 5,404
  • 9
  • 44
  • 80
0
votes
1 answer

How to solve not null constraints

My models.py file is as following Class Project(models.Model): ABI_choices = ( ('android-tv/x86','android-tv/x86'), ('abi_2', 'google_apis/x86'), ('abi_3','google_apis/x86_64'), ) Screen_size = ( (1,"Landscape"), …
Mutasim Fuad
  • 606
  • 2
  • 12
  • 31
0
votes
1 answer

Maximum recursion depth trying to create Django migration

When I try to generate an initial migration for my Django app with: python manage.py makemigrations myapp I get a traceback like: File "/myproject/.env/local/lib/python2.7/site-packages/localflavor/us/models.py", line 21, in deconstruct name,…
Cerin
  • 60,957
  • 96
  • 316
  • 522
0
votes
0 answers

django: AttributeError: 'DatabaseWrapper' object has no attribute 'introspection'

I'm using django1.10, python3.4. When trying to use migrations for the first time (Project was django1.6 python2.7), I get the following error: (venv) ruben@erd959:~/Projects/prot-zboss/zboss$ python manage.py makemigrations utils Traceback (most…
Ruben
  • 1,065
  • 5
  • 18
  • 44
0
votes
0 answers

Django: how to completely skip a migration?

I want to be able to not run a Django 1.8 migration. I have seen people use the --fake option, but it's not a valid alternative for me, since it writes a new record on the django migrations database table. I dont like this, because I want to be able…
Xar
  • 7,572
  • 19
  • 56
  • 80
0
votes
1 answer

Django 1.10 - how to load initial users

What is the right way to load initial users in Django 1.10? When we talk about our own django app then it is recommended to have a /fixtures/initial_data.json (as mentioned here). But in the case of User, where django.contrib.auth is not our app,…
user3139774
  • 1,295
  • 3
  • 13
  • 24
0
votes
1 answer

Retrieve the last migration for a custom migration, to load initial data

I created a custom migration "0000_initial_data.py" and I want that to get applied after all the other migrations are done. Though when I try to use ____latest____ in the dependencies I get "dependencies reference nonexistent parent node" error I…
0
votes
1 answer

Django migrations gives error when run separately in different machines

We are a team of developers working on Django project. We are facing issues with django migrations. if one developer makes changes in model and runs makemigrations>migrate sequence it generates some sqls in migrations directory. Now when other…
timedout
  • 541
  • 1
  • 4
  • 12
0
votes
1 answer

Risk to overwrite tables via Django Models migrations?

I'm currently trying to update my Django models to incorporate some new functionality but after runnning "makemigrations", the console output makes me worried I'm going to overwrite other tables in the database. Essentially, in my models.py, I have…
Rob
  • 89
  • 1
  • 1
  • 8
0
votes
1 answer

Why does my Django app attempt to create migrations, when it is defined to not allow migrations in a router?

I've got a Django app called dataapi which is built by introspecting a PostgreSQL database to write various models files (one for each schema). It works and provides us read-only access to the data we need via the ORM, but I break up models into…
FlipperPA
  • 13,607
  • 4
  • 39
  • 71
0
votes
0 answers

Migrate django model primary key and cascade to related objects

I have two models as shown below. ArticlePost is related to Article by a Foreign Key. I'm wanting to remove name as a primary key on Article and instead have the Django default id field. What is the best steps to do this so that all related…
0
votes
1 answer

Django model deconstruct() method

Can someone give a solid example of the deconstruct() mentioned in https://docs.djangoproject.com/en/1.8/topics/migrations/#migration-serializing. I read the doc, and can't really understand with an example.
user1187968
  • 7,154
  • 16
  • 81
  • 152
0
votes
1 answer

Can't do migrations - ... has no field named 'questions'

I'm trying to figure out why does Django return's this error when trying to migrate after makemigrations. I tried to change related names and delete last migrations but nothing works. Maybe you see what's the problem? Error after migrate:…
Milano
  • 18,048
  • 37
  • 153
  • 353
0
votes
2 answers

django migration - re-creating the database

I am running python 2.7 and django 1.8. I have this exact issue. The answer, posted as a comment is: What I did is completely remake the db, erase the migration history and folders. I am very uncertain about deleting and creating the database. I am…
user1261774
  • 3,525
  • 10
  • 55
  • 103