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.
1,350
questions
0
votes
0
answers
29
views
Django test with multiple databases without a default connection [duplicate]
I've created a cut down scenario from scratch to hopefully find a solution to what I have witnessed in some production code - which has stopped me dead in my tracks.
The code is here:
https://github....
0
votes
1
answer
29
views
How to Add field with default value, without triggering full rewrite of table?
I want to add new field in existing model
current Model
class InfoModel(models.Model):
id = models.UUIDField(default=uuid.uuid4)
New Model
where I want to add new field count
class InfoModel(...
0
votes
0
answers
23
views
Django Migrations in CI/CD pipeline
My CI/CD pipeline is triggered whenever there is a code push. There is an already populated database(PostgreSQL). I am doing changes in models.py (specifically adding a new model) and python manage.py ...
1
vote
1
answer
32
views
Migrate / MakeMigrations conundrum
I have a wagtail app that deployed to docker, but then I get a very strange error, below are the steps:
Step 1:
docker-compose run app /venv/bin/python manage.py makemigrations`
Migrations for '...
1
vote
0
answers
26
views
Django migrate primary key from UUID to Slug
I have model AAA with UUID as primary key. Many models have relation to this model.
Now I want to migrate them to use Slug as this primary key, to keep slug value in database as a reference.
What will ...
0
votes
0
answers
14
views
Accidently Deleted Django Migrations Table
Can someone please help me? I have accidentally deleted Django migrations table from DB.
How do I recover that?
DB - Postgress
0
votes
2
answers
27
views
Django set environment variable via command line and use in Migrations
Following on from this question - Specify a .env file in Django in command line or vscode launch.json. So we have an environment file for dev, test, and production - which is specified in an ...
0
votes
0
answers
21
views
Django Migration to add Group and permissions not adding permissions
I have a custom migration that is intended to automatically create a new group and add permissions. The group is being created but the permissions are not being added. Any ideas about how to fix this?
...
1
vote
0
answers
84
views
+50
Django standalone apps with one app depending on another app - django.db.migrations.exceptions.NodeNotFoundError
I am using Django 4.0
I have written two standalone apps. Foo and FooBar.
Application Foo uses package django_nyt. Application FooBar uses functionality from application Foo.
I am able to ...
0
votes
0
answers
18
views
Create new schema in django migration file
How to create a new schema using Django migration file?
I dont see any migrations.CreateSchema() option just like there is migrations.CreateModel()
Currently the way I do this is in my migration file ...
0
votes
0
answers
10
views
Django Insert Migrations Code Programmatically
I am working in a huge project in Django.
Every model have two fields "company" and "branch".
I deleted "branch" fields and make company model hierarchically .
The ...
0
votes
1
answer
43
views
Migrations Error in Django: AttributeError: 'str' object has no attribute '_meta'
I know this has been asked before. But, I tried the available solutions. Those don't seem to work in my case unless I missed something unintentionally.
I dropped all the tables/relations from the ...
0
votes
0
answers
25
views
no such table: two_factor_phonedevice when using django-two-factor-auth==1.14.0 and --nomigrations
I have a 2.2 Django project with django-otp==0.8.0, django-two-factor-auth[phonenumbers]==1.14.0, and an app two_factor_auth that makes use of these two libraries.
When tests are run with migrations, ...
0
votes
0
answers
29
views
Makemigration with django4.0.6 and python3.10.5 doesn't work
I'm currently coding a blog as a side project, whenever I make a considerable modification in my models, I cannot migrate.
This is my model
from ckeditor.fields import RichTextField
from django....
0
votes
1
answer
31
views
Django migration: got relation does not exist or relation already exists errors
I tried to port a Django app from one server to another and change database engine from sqllite3 to postgres. After I pulled the app from github to the new server and reconfigured database settings ...
0
votes
0
answers
21
views
Getting django.db.utils.ProgrammingError: (1146, “Table ‘password_management.accounts_workspace’ doesn’t exist”) while making db migrations
I am trying to make migrations by running the following command:
python manage.py makemigrations
But, I am getting the below error:
django.db.utils.ProgrammingError: (1146, "Table '...
0
votes
1
answer
68
views
Test a data migration ManyToMany in Django
I tried to add a field to my ManyToMany relationship models in Django.
So step by step, I created the new model and apply makemigrations and migrate.
I checked I have the new table in my postgresql ...
1
vote
1
answer
30
views
Test whether a Django migration has been applied to a DB
I have a django project, and I wish to update a MySQL database from a previous version of the codebase to be compatible with the current version.
I have all of the migrations for the project, but I do ...
0
votes
0
answers
25
views
Should I run makemigrations on django project or individual apps?
If I have multiple apps in a django file:
├── app
│ ├── __init__.py
│ ├── admin.py
│ ├── apps.py
│ ├── forms.py
│ ├── migrations
│ ├── models.py
│ ├── tests.py
│ ├── urls.py
│ ├── ...
0
votes
1
answer
28
views
Error while makemigrations, relation for custom user
I am currently in the middle of this project and the makemigration command is throwing an error.
Previously I used migrated but it worked fine. The error line it is showing was added before and was ...
1
vote
1
answer
36
views
Django: Linking Models in different apps gives circular import error
I have two apps in my project names quiz_app_teacher and accounts
many models from these files are connected with each other, but when i try to migrate I get this error
File "F:\self\quiz_site\...
1
vote
1
answer
24
views
How to run migrations for a specific tenant/schema in Django multi-tenant framework?
The tenant_command was not working properly according to my requirements.
So, I found out this solution after tweaking the command below
python3 manage.py tenant_command migrate --schema=schema_name
1
vote
1
answer
48
views
How to properly migrate a monolith architecture app to a microservice app in Django
Today I come with this question probably to someone who has large experience in this.
Basically what the title indicates. We have that app and we have to migrate it to microservices.
We didn't find ...
0
votes
0
answers
40
views
Django: Broken migration => remove old migration files [duplicate]
I was trying to remove on my dev machine old migration files with
manage.py myapp zero
But it failed at some point and I messed up. I have a project with ~1000 migration files.
Unfortunately I have ...
0
votes
1
answer
29
views
Remove inheritance from model retaining IDs
I have a two classes, one of which inherits from the other
class Drink(models.Model):
....
class Juice(Drink)
....
Now, this was a mistake and I would like to remove the inheritance and have ...
1
vote
0
answers
27
views
Dajngo all migrations are doubled
I just started my django project and after running the migrations I was trying to create superuser. Then the error popped out that I have unapplied migrations (even though I just did it). When I ...
-1
votes
1
answer
20
views
Django DB Migration InconsistentMigrationHistory when running migrate
I am unable to migrate my django after running python ./manage.py migrate.
This is what showmigrations is displaying
customerweb
[X] 0001_initial
[X] 0002_user_industry
[X] 0003_auto_20220209_1737
...
1
vote
0
answers
75
views
Do you think this is the right way to rename a django app?
I read different threads and tutorials on renaming and migrating a Django app (How to rename a Django app and migrate data from an app to the other for instance), I also tried to use the django ...
0
votes
1
answer
32
views
How and where to call post_migrate where Django's own Permission model is the sender
In my current project I want to use Django Group model objects as access roles.
I'm trying to programmatically assign permissions to the group instances that should have them (for example, '...
1
vote
1
answer
34
views
Avrage rating calculation not working after migration django
My code was doing what it should before the migration of calculating the avrage rating.
After a migration it just dident calculate the avrage rating. It seems like the migration dident notice the code ...
1
vote
1
answer
24
views
How to update data in Database when status_choice removed from models
In models I had status choices for
status = models.CharField(max_length=50, default="FIELD_1", choices=STATUS)
like this:
STATUS = (
('FIELD_1', _('value FIELD_1')),
('...
0
votes
0
answers
25
views
The field oldapp.MyModel.related was declared with a lazy reference to 'oldapp.related', but app 'oldapp' doesn't provide model 'related'
Similar questions have been asked before, but none are applicable to my situation as far as I can tell.
I followed this answer to move the model Related out of oldapp and into newapp.
I created the ...
0
votes
1
answer
32
views
Populating db with initial data in Django
I need a way to populate db with initial data(cities) for my refs. So I've tried to do it through migrations(https://docs.djangoproject.com/en/4.0/topics/migrations/#data-migrations)
Not sure it's a ...
3
votes
0
answers
53
views
Referencing external variables in Django data migrations
When using models in migrations, in Django we can use apps.get_model() to make sure that the migration will use the right "historical" version of the model (as it was when the migration was ...
0
votes
2
answers
50
views
Problem in panel of Django3.0 after migrations
Why is the error appearing in django/admin? Migrations ok, I need to have 3 items in the table where I will have results.
class Robot(models.Model):
"""Robot model, speed and ...
1
vote
1
answer
68
views
Django Model isn't migrating even after i saved and added app to installedApps
from django.db import models
from django.contrib.auth import get_user_model
user = get_user_model
# Create your models here.
class Post(models.Model):
title = models.CharField(max_length=200)
...
1
vote
2
answers
42
views
How can I inherit another model after creating one with models.Model, [(models.Model) ---> (BaseModel)]
I created a model like this.
class BloodDiscard(models.Model):
timestamp = models.DateTimeField(auto_now_add=True, blank=True)
created_by = models.ForeignKey(Registration, on_delete=models....
0
votes
0
answers
35
views
Where is the Django Migrations model?
I wish to make a custom model, which has a foreign key relationship to the django_migrations table. Can this be done? if so, exactly how do I import the django migrations model?
Edit... Here is my ...
0
votes
0
answers
38
views
Best way to change the primary key for a table in an existing project?
I have an existing Django project with some important data in the database.
But I would like to change the primary key of the main table.
How should I do it? (I am new to Django, so any newbie advice ...
0
votes
0
answers
21
views
Why does the set method in the many-to-many field through a custom model not work but add method does?
I have these models:
class PackRepo(BaseModel):
title = models.CharField(max_length=256, verbose_name='Title')
class PackVersion(ModelWithUID, BaseModel):
repositories = models....
0
votes
1
answer
51
views
Deploy django react app to heroku: Migration error ?: (staticfiles.W004) The directory '/app/static' in the STATICFILES_DIRS setting does not exist
My deployed website right now just shows the Django Rest Framework Page with none of my css or data (https://ever-actor.herokuapp.com/api/lines/)
I'm thinking it has something to do with the ...
0
votes
1
answer
338
views
Django ValueError: field admin.LogEntry.user was declared with a lazy reference to 'app.user', but app 'app' doesn't provide model 'user'
I have a similar problem to this post but its only answer didn't help:
❯ python manage.py makemigrations
No changes detected
Because when I execute python manage.py migrate I get the following ...
0
votes
0
answers
32
views
What causes this hanging command prompt in a Django project
This hanging prompt on any commands that involve migrate, makemigrations etc.
I have other Django projects that work fine and I have no idea what is making it do this on this one.
Since I had no data ...
0
votes
0
answers
26
views
Django dumpdata can`t put Cyrillic characters into data file
while making python manage.py dumpdata(doesnt matter what format I choose) I got strange data instead of Cyrillic words:
pk: 5
fields:
name: ┼ъчюЄшўэ│ Ёюёышэш
slug: exotic-plants
parent: null
lft: 1
...
0
votes
1
answer
73
views
django.db.utils.ProgrammingError: relation "app_bugs" already exists
After I deleted all the migration files and made them again using "python3 manage.py makemigrations" and "python3 manage.py migrate", the following error occurred:
root@chat-...
-1
votes
1
answer
33
views
django.db.migrations.exceptions.NodeNotFoundError: Migration app.0172_auto_20220603_1746 dependencie _auto_20220601_2313')
I deleted some migration files that were giving me the error.
Then when I write "python3 manage.py showmigrations" I get the following error:
root@chat-manager:/var/www/jinabot# python3 ...
1
vote
1
answer
34
views
Django migrations.RenameField creating new field instead of renaming existing one
I edited a fresh migration file to instead of adding a new field, just rename a field that already exists on the Django Model
This was the only change on this field
migrations.RenameField(
...
1
vote
1
answer
86
views
django.db.utils.ProgrammingError: cannot cast type integer to date
Hello guys i have some problem with PostgreSQL when i deploy from docker.
Error:
django.db.utils.ProgrammingError: cannot cast type integer to date
[2022-06-01 09:06:04] LINE 1: ...a_playlist" ...
0
votes
0
answers
22
views
How to fail a custom data migration?
I have written a data migration that initializes new tables with some rows. The objects have foreign keys to other tables, so I have to check that the foreign ids exist. If they don't, I would like to ...
0
votes
0
answers
19
views
How to create postgres db index for a jsonfield in Django using the ORM?
I made a migration and added this exact sql:
migrations.RunSQL("CREATE INDEX my_json_idx on my_table((my_json_data->'id'));")
It works.
All i'm trying to do is, get this exact equivalent ...