Migrate two different models from two different Django applications - python

Hi guys so i have a Django project with two application named, shopper, parcel, each of this app have one model also named Parcel and Shopper. there is a one-to-many relationship between the 2 models. the problem is i want to migrate the two models, if I was just one i could have gone with the normal way of migrating a model.
This is what i have tried
python manage.py makemigrations parcel
python manage.py migrate
the problem with the first one is it does not take the other models in the shopper app into consideration and that is not what i want.
python manage.py makemigrations parcel
python manage.py migrate
python manage.py makemigrations shopper
python manage.py migrate
this was my second solution, the commands end up creating migration of each model but still i don't think that is the right thing to do.
Any help in the right direction please

Related

Django models does not create table after I clone it on github

Recently I'm doing a small Django project that I have to work with my teammates,
so I clone the project's repository from github.
The problem is , the database in my computer doesn't have the table so i think i have to makemigrations and migrate it. But after i did that,django only createed its own tables but didn't create other tables that my teammates wrote in Django's models.
I really need your guys hlep
this are the models my teammates wrote
but after i makemigrations and migrate it ,phpmyadmin does not show the tables i want
makemigrations and migrate
the picture on phpmyadmin after I migrate django models
This is my settings
after tried this,it still not working
migrations folder
You should use managed=True in all models for managing the migrations via django
run
python manage.py makemigrations *name_of_you_app_that_has_models_here*
python manage.py migrate *name_of_you_app_that_has_models_here*

How to migrate/makemigrations in one app with multiple databases

I'm working on a django project with:
One single app
Three huge identical mysql databases with historical data
One mysql database where I store results from calculations of the historical data
I'm struggling with how to makemigrations/migrate when I make changes to the models.
With only one database I would simple do something like:
$ manage.py makemigrations <app_name>
$ manage.py migrate <app_name> 0001
But this creates tables for every model in every database. I've tried to mess around with:
$ manage.py migrate <app_name> 0001 --database==<name_of_db>
But is this all I should do? I have looked into routers but I don't really understand how to configure one for this case.
In short: My goal is to be able to update a model and then only migrate the changes to the relevant databases. In some cases the updated model should migrate to the three identical databases, in other cases the updated model should only migrate to the one unique database.
All help would be appreciated!
i found this django docs. i think its helpful

Why should we use three migration commands to migrate our database succesfully?

I was working on models in django and after creating classes for models and when migrating them I was supposed to use three commands for completing migration of models. The commands are :python manage.py migrate,python manage.py makemigrations <app_name>,python manage.py migrate
So my question is that why should we use three commands like this ?
From the django docs,
migrate: which is responsible for applying and unapplying migrations.
makemigrations: which is responsible for creating new
migrations based on the changes you have made to your models.
If you make changes to your model use python manage.py makemigrations followed by python manage.py migrate.
Incase of initial migration just after you create an app you dont need to python manage.py makemigrations but just python manage.py migrate works.

django migration don't work on server

I had a app where there were models and that site I have deployed. Now I have added 2 models in the app. Unfortunately my migration was deleted in local and after adding the models I again generated the migration with 2 new models.
It gives me 0001_initial.py where I can see my new models too. Now I updated my this file in server. But when I did python manage.py migrate it says "Some of your model has been changed but not reflected so do manage.py makemigrations and manage.py migrate"
I tried "python manage.py migrate" but it says same thing. I am unable to get these models. I have even tried "python manage.py syncdb" but same error.
I have registered these models in admin so in admin I am seeing these models but when I click it my servers get hang. I think because my models are not synchronised or my new tables are not created.
In my migration i can see the new models too but when I do "manage.py migrate" i get errors that I should migrate first and re-migrate.
Is there anyway so that I can compel my app to use that migration forcefully where I have my new models too.
I am trying this from hours but no solution. Need help

How to add a field in Django model?

In Django, if I have a model which has 4 fields, but now I want to add a new field, how do I keep the data in the old model?
use South
pip install South
firstly, keep your django models match your current database tables exactly, then run:
python manage.py schemamigration myapp --initial
python manage.py migrate myapp --fake
#Make changes to your django model (add new field)
python manage.py schemamigration myapp --auto
python manage.py migrate myapp
You'll need to perform a "migration", and the current best way to do this in Django is with a tool called South.
Check out their tutorial. Make sure you make a copy of your db before you do this, since you may mess something up if it's your first time using South.

Categories

Resources