Reputation: 424
I wanna use 'db1' for app 'app1', and 'db2' for 'app2'. (I don`t need any synhronization between ths applications and databases. They independent but lay in one 'mysite' django project.)
I have migration for 'db1' in 'app1'. /app1/migrations/0001_initial.py. It contain classes for 'db1' ('default') structure.
Now - I appended database 'db2' to settings.py DATABASES dict. 'app1' use 'default' database. (db1 is 'default') - I made $startapp 'app2' folder - I put 'app2.apps.App2Config' to INSTALLED_APPS list - I executed $makemigrations app2 app2/migrations/ folder is empty (only init.py where) Any makemigrations exectuions now write:
No changes detected in app 'app2'
I running $migrate --datbase=db2 It writing:
Operations to perform: Apply all migrations: admin, auth, contenttypes, db1, sessions
Running migrations: Applying contenttypes.0001_initial... OK
Applying auth.0001_initial... OK
....
....Applying db1.0001_initial... OK
And nothing is changing. No any mention about 'db2', no migrations upgrade as i see, the app2/migrations folder is empty yet.
What i have to do for make models for 'db2' and use it in 'app2' code? Thanks
Upvotes: 0
Views: 104
Reputation: 424
Nessasary to 'makemigrations' for app2 with DATABASE_ROUTERS in settings.py: [docs.djangoproject.com/en/1.10/topics/db/multi-db][1]
'migrate' function work without one, but 'makemigrations' must have router.py file with Class App2Router(object) spcified for 'app' & 'db2'.
If makemigrates has completed - 0001_intial.py present, and now you may to migrate --database=db2
Upvotes: 0