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

No model tables are created for a Django migration

I have searched other articles (like this one) for a solution, but nothing has helped so far... I realized while working on my project that I needed to alter the model, changing a primary key to an AutoField rather than use a custom field. I knew…
Tim S.
  • 2,187
  • 1
  • 25
  • 40
0
votes
2 answers

Migration issues in python django?

I have MySQL database in backed but when i change any model i does not reflect in backend python manage.py makemigration app_name python manage.py migrate but it show no migrations applied does mysql does nor support migrations my model class…
user7889642
0
votes
1 answer

What is the best way to handle functional django model field defaults?

Sometimes a ForeignKey field needs a default. For example: class ReleaseManager(BaseManager): def default(self): return self.filter(default=True).order_by('-modified').first() class Release(BaseModel): default =…
0
votes
2 answers

Django 1.10 - It is safe to delete non-processed migration file?

I created a migration file using python3 manage.py makemigrations my_app. However I ran that command by mistake. Is it safe just to delete the newly created non-processed migration file? Or is there something else that needs to be done?
Fusion
  • 5,046
  • 5
  • 42
  • 51
0
votes
0 answers

Django (1.10.4) Migrations not applying datetime field changes(copies) in runpython

Changes in runpython are never applied for datetimefield. I'm adding a new datetimefield on a model with an optional default of timezone.now() model date = models.DateTimeField(default=timezone.now) migrations operations = [ …
grandlubs
  • 21
  • 5
0
votes
2 answers

Custom sql in django migration doesn't work

I'm trying to run custom SQL in my migration. This is how it looks like: from django.db import migrations class Migration(migrations.Migration): dependencies = [ ] operations = [ migrations.RunSQL( "SET timezone TO…
NST
  • 724
  • 9
  • 20
0
votes
0 answers

Load data file into Django with one demo user

I am new to Django. I am planning to a have a demo user account and i want to load data based on demo user's UUID(user's id). Is there another way to load the seed file without using fixtures? seed file. User.objects.create( first_name =…
user7508299
  • 31
  • 1
  • 4
0
votes
0 answers

Django deployement partial migrations issues?

I was facing issues to efficiently replicate database changes on production. the best solution I can find is to gitignore migrations files so that I can isolate migration process on production. any better solutions to securely push model changes…
0
votes
1 answer

Django multiple databases error with routes

I'm using 3 databases in my project: DATABASES = { 'default': { (postgres, read, write)... }, 'admission_db': { (postgres, read, write)... }, 'journals_db': { (mysql, read only)... } } DATABASE_ROUTERS…
IlyaChch
  • 11
  • 4
0
votes
1 answer

django migrations - get migrations from location on disk

I have a django project but i want to get the migrations from a different location (not the project itself). I tried to use the MIGRATION_MODULES in the settings page but i could only make it work with different in project modules. I want to be able…
Mr T.
  • 4,278
  • 9
  • 44
  • 61
0
votes
2 answers

Deleted Migration folder (Django 1.8) by accident what are my options?

I have accidently deleted one of migrations folders and and have no backup for it. What are my options? DB is postgres. Right now everything is OK.(I have moved instead migration folder I have on my DEV server with SQL lite) So I am just getting…
Ilya Bibik
  • 3,924
  • 4
  • 23
  • 48
0
votes
2 answers

django migration impossible because of bug in field default value?

I am facing a strange situation with one of my django models. I am using Django 1.10.3 with python 3.5.2. The model looks like this (simplified for clarity): class Report(models.Model): date = models.FieldDate() def fieldA_default(self): …
Laurent S
  • 4,106
  • 3
  • 26
  • 50
0
votes
1 answer

Is there a way to specify the database alias that is concerned by a RunPython operation in a Django migration?

I have a Django project that uses two databases. I defined a Database Router and everything works fine when running migrations, except for RunPython migration operations : in this case I have to "manually" check in the RunPython code function on…
rparent
  • 630
  • 7
  • 14
0
votes
1 answer

django admin reises FieldDoesNotExist on renamed field

sorry for newbie question, but I can't understand why this happen and how to fix it. I created Comment model class Migration(migrations.Migration): dependencies = [ ('myblog', '0001_initial'), ] operations = [ migrations.CreateModel( …
LinearLeopard
  • 728
  • 1
  • 6
  • 18
0
votes
1 answer

Migration fails when extending Django User Model

I'm trying to extend django User model by inheriting AbstractBaseUser so i can be able to manipulate the authentication process of the project. Here is what my model looks like. class AccountManager(BaseUserManager): ... create_user ...…
Shift 'n Tab
  • 8,808
  • 12
  • 73
  • 117