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

Django: cannot add foreight key to User

I am using ldap to do authentication, just like Understanding Django-LDAP authentication. My model is: class MyFile(models.Model): file = models.FileField(upload_to="files") slug = models.SlugField(max_length=50, blank=True) user =…
BAE
  • 8,550
  • 22
  • 88
  • 171
0
votes
1 answer

Django migrate unique field between models with data

Let's assume I have this models structure: class User(AbstractUser): first_name = models.CharField(max_length=40, blank=True) last_name = models.CharField(max_length=40, blank=True) class UserProfile(models.Model): uuid =…
mdargacz
  • 1,267
  • 18
  • 32
0
votes
1 answer

Django - migrate before setting custom user model, error message

I have forgotten to set my custom user model in the settings file and migrate my project first time. Now i am trying to make migrations again after setting my custom user model with errors -> ... django.db.utils.ProgrammingError: relation…
ratata
  • 1,129
  • 14
  • 42
0
votes
2 answers

loaddata raises IntegrityError when called within migration, but works if called from the CLI

For my Django 1.8.12 site I have an example_content fixture which fills in some initial site content. If I load this this right after running migrate it imports fine: $ ./manage.py migrate --noinput Operations to perform: Synchronize unmigrated…
0
votes
0 answers

Django - creating a DB scheme from model inspite of existing code

I'm using Django 1.9 and somewhere in the development process the migrations tool stopped working and was throwing strange errors, therefore I wanted to start off with a new database (MySQL). So I removed all old migrations, created a new initial…
Jarno
  • 6,243
  • 3
  • 42
  • 57
0
votes
1 answer

Error after creating a foreign key: django.db.utils.IntegrityError: MyApp_job__new.level_id may not be NULL

I've created a new attribute level in my model. I've forgot to put there null=True before migrations. When the cmd asks whether I want to put a default value, I've typed None. Now, I can't do migrate. So I tried to remove level column and do new…
Milano
  • 18,048
  • 37
  • 153
  • 353
0
votes
1 answer

django makemigrations for a different database that is not configured

I'm working on a project that requires us to turn in mysql scripts of our database. Is there a way to tell Django to make MySql migrations instead of SqLite migrations, without configuring/connecting to a mysql server?
Grant
  • 43
  • 6
0
votes
1 answer

Confused migration in django

I have a little unusual migration to do in my django website: I need to restore a database with older configurations, because the old website is still working and i need it's data. When i finish the restore process, how will i migrate it? Can i run…
0
votes
1 answer

How can I debug Django ORM/SQL issues? (fresh migration gives null value error, existing db has broken data)

So, in a bit more detail I have a model with a field like: permalink = models.IntegerField(default=0) I've not actually been using this field - but would now like to. However, it seems all models on this table, permalink is now 57295730 - on all…
Chozabu
  • 1,015
  • 1
  • 10
  • 33
0
votes
1 answer

Django addField ForeignKey during migrations create unusable constraint name

Env: Django 1.8.11 + Postgis I'm adding some ForeignKeys on a MyModel. The models pointed are in another schema ("cartography"). makemigrations no errors migrate One error. Can't create the constraint because the generated name. But I'm adding 10…
Gromish
  • 189
  • 2
  • 9
0
votes
1 answer

Duplicate column name after altering a field

I added a textfield "field2" to a model and later modified it to a ForeignKey. After which when I try to run migrations, i get duplicate column name for field2. How can this be resolved. Also, i have one more field which is a foreignkey. Here is my…
0
votes
0 answers

Django migrate fail after adding new field or modifying an existing one but I don't want to delete my DB columns

I have to things that bother me and make me wondering if I really understood django or not. first of all I changed a little thing in my model : article_country = models.ManyToManyField(Country, verbose_name=_('Country of the article'), …
Jay Cee
  • 1,855
  • 5
  • 28
  • 48
0
votes
0 answers

Django FieldError in the app that is not installed

I have two django apps: 'home' and 'user_profile'. I made changes to 'user_profile' app and I want to makemigrations for it, so I write manage.py makemigrations user_profile And I got this error: File "D:\example\project\home\forms.py", line 31,…
0
votes
1 answer

How to export (create a migration) a flatpage (.txt) into a database?

I am using Django and created some flatpages via the admin panel, then I export them to my project in a .txt format using: python manager.py export_flatpages 1 > my_flat_page.txt Since I am working remotely, I need my peers to be able to quickly…
carlosbvz
  • 163
  • 2
  • 14
0
votes
2 answers

Getting OperationalError: no such function: version when running syncdb for the first time

I'm setting up a new environment for an existing Django codebase. However, I am unfortunately unable to successfully complete a ./manage.py syncdb or a ./managage.py migrate. Here is my error output, including full traceback: ./manage.py…
James Rasmussen
  • 651
  • 1
  • 9
  • 22