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

graphene code run before django data migrations

I wrote a piece of code that generates graphene input object type dynamically from the database. when I try to run ./manage.py migrate that code runs before the migration and caused django.db.utils.ProgrammingError I have the same issue in run the…
-1
votes
1 answer

Is it possible to use the same database for two Django projects containing different models?

We planned for two Django projects. Say, Project-1 contains Model A and B. and Other Project-2 contains Model C and D. But I am afraid if it possible or not as I am new in the Django World. Your suggestions would be highly appreciated.
-1
votes
1 answer

Django migrate throws AttributeError: 'str' object has no attribute '_meta'

After doing some extensive changes in the DB schema, I ran makemigrations. It created migrations successfully. But then migrate failed with: AttributeError: 'str' object has no attribute '_meta' What went wrong? Here is the full traceback: $…
frnhr
  • 12,354
  • 9
  • 63
  • 90
-1
votes
1 answer

How to do connection or migrations between different MySQL databases and Different Django App's?

I am new to Django, your help would be greatly appreciated. please let me know what mistakes i am making. can someone give me an example with at least 2 apps and 2 Databases. I have 3 apps cherry, apple and mango in my Django project. For every app…
SSS
  • 73
  • 11
-1
votes
1 answer

(1054, "Unknown column '' in 'field list'")

I know this question has been asked a couple of time but no previous answer was able to solve my problem. I had a perfectly working model in Django that looked like this: class Template(models.Model): mat = models.CharField(max_length=50,…
chenard612
  • 101
  • 2
  • 15
-1
votes
1 answer

Reverse sql that undo a query

query: UPDATE "table_name" SET properties = properties || jsonb_build_object('$ip', ip) WHERE ip IS NOT NULL; I am running a Django migration, I need the reverse sql that undo the results of executing this query and restores the table in the…
futurenext110
  • 1,991
  • 6
  • 26
  • 31
-1
votes
1 answer

Can no longer drop database and reapply migrations in Django?

Throughout writting my app many times I have had to delete my database and re run my migrations. This has always worked by simply deleteing the database file then just running manage.py migrate . However now when I try to do this, I get an error…
-1
votes
2 answers

Scaling or avoiding migrations when using Django 2.x?

I'm just beginning my journey with Django framework and I read that Django developers have made using migrations mandatory beginning from version 2.0. I might be old school but I like my database separate from my code. I have always kept my database…
dicemaster
  • 1,203
  • 10
  • 22
-1
votes
2 answers

Tried so many things regarding Django migrations issue but still I can,t fix this error?

Hey guys I'm getting an error with migrations from past two days.I added a new field into a model and then I tried to run makemigratons It worked fine but when I tried to migrate then I got a datetime error.After much effort i had to finally delete…
-1
votes
1 answer

How to give database name in runtime and migrate all changes to it

How to migrate changes in a database who's name is user defined. i tried giving data = request.data cursor = connection.cursor() cursor.execute("create database " + data["database"]) DATABASES["default"]["NAME"] =…
-1
votes
1 answer

Django-migrate-Error: `ValueError: invalid literal for int() with base 10: ''

I am a django-beginner and I don´t understand this error nor explanations from other posts: ValueError: invalid literal for int() with base 10: ''. How can I fix it? My Traceback: PS C:\Users\Tobi\Desktop\LeftLife\instapic> python manage.py…
-1
votes
1 answer

How to execute git command through Django migration?

I have the requirement to execute a git command in a Django migration. I need to clear the contents of a directory via a Django migration because we do not have access to the production server directly. Being new to both Django and git, I have no…
Venu Saini
  • 427
  • 2
  • 6
  • 19
-1
votes
1 answer

"Wrong number of constraints" when refactoring models to another app

After refactoring some models in a bloated app (everything in appname/models.py) into a subfolder application (some of the models in appname/subapp/models.py) and running makemigrations, I'm getting the following error when running manage.py…
andyn
  • 577
  • 1
  • 6
  • 18
-1
votes
1 answer

Collapsing duplicate foreign key values in Django migrations

I have a Django app that I need to perform a migration on. Here's a representational schema of what I need to modify: class A(Model): c = ForeignKey(C) ... class B(Model): c = ForeignKey(C) ... class C(Model): x = CharField() …
rrauenza
  • 6,285
  • 4
  • 32
  • 57
-1
votes
1 answer

Problems with media and migrations

have problems. 1)In production Django tries to access photos at http://"ip_address"/images/"image".jpg URL however images must be in http://"ip_address"/media/images/"image".jpg 2)I have added two more fields (alt and text) to existing model.…
mightycoder
  • 71
  • 3
  • 12
1 2 3
97
98