Saturday 15 August 2015

python - django Multiple db with read only -


What can I mean in this document is very kind to convince me:

I Added in my project / settings.py

  database = d '{' default ': {' ENGINE ':' django.db.backends.postgresql_psycopg2 ',' NAME ':' testdb ' , 'USER': 'test',}, 'db2': {'ENGINE': 'mysql.connector.django', 'NAME': 'db2a',}}  

This command works only when I change the default with DB2:

  dragon manage.py inspectdb & gt;  

Now when I get models from DB2, how can I read them, switch the DB2 and the default back to them?

1) If I try to migrate, they see all the new models, but then they try to pile them, and I must read them because they already exist. .

We now have to handle routing. First of all, we need a router that knows to send questions to auth app for auth_db

2) ) Which file should be added to the AuthRouter (object): ? I import settings from django.conf class db_Router (object) to settings.py? Next to

  can add a file named routers.py: def db_for_read (auto, model, ** signal): return 'db2' def db_for_write (self, model, ** sign) Return 'defaults' def allow_relation (self, obj1, obj2, ** sign): db_list = ('default', 'db2') if obj1._state.db db_list and obb2: db_list in obj2._state.db Returns the correct returns Also def def_migrate (self, db, model): Return True def allow_syncdb (auto, DB, model): If DB == 'db2': return model._meta. App_label == 'Epipodbie 2' Alif model._meta.app_label == 'Epophoda 2': return wrong return no.  

Should this work? Or am I completely out?

Just answer your own:

1) python manage.py Inspectdb --database = db2 & gt;

2) Create a routers.py file in the root folder of the project

Everything worked like a charm!


No comments:

Post a Comment