Here's something else I found, the second time around I run django migrations, the model does get created in the mysql db. Once it has popped in the error I guess it has already created a database table with the unique field constraint. However I then have to fake initial to get the django_migrations to tick the migration as done.
regards [image: --] Maninder Kumar [image: http://]about.me/maninder.s.kumar <http://about.me/maninder.s.kumar?promo=email_sig> On Mon, Feb 24, 2020 at 12:20 AM Integr@te System <datacentral...@gmail.com> wrote: > Hi, > > Would u consider any relative details with result!? > > Or try some cmd to more status: > https://docs.djangoproject.com/en/2.2/topics/migrations/ > > On Mon, Feb 24, 2020, 00:43 maninder singh Kumar < > maninder.s.ku...@gmail.com> wrote: > >> I am working on an application with two databases and two different >> dbRouters. On migrating a model with a OneToOneField I get the following >> error : >> >> django.db.utils.OperationalError: (1824, "Failed to open the referenced >> table 'auth_user'") >> >> >> The auth dbRouter is for the [auth, sessions, contenttypes, admin] apps >> while the Redford dbRouter is for the main app. >> >> Below is the code for the routers : >> >> >> *auth dbRouter* >> >> >> class AuthRouter: >> """ >> A router to control all database operations on models in the >> auth and contenttypes applications. >> """ >> route_app_labels = ('auth', 'contenttypes', 'sessions', 'admin') >> >> def db_for_read(self, model, **hints): >> """ >> Attempts to read auth and contenttypes models go to auth_db. >> """ >> if model._meta.app_label in self.route_app_labels: >> return "default" >> return False >> >> def db_for_write(self, model, **hints): >> """ >> Attempts to write auth and contenttypes models go to auth_db. >> """ >> if model._meta.app_label in self.route_app_labels: >> return "default" >> return False >> >> def allow_relation(self, obj1, obj2, **hints): >> """ >> Allow relations if a model in the auth or contenttypes apps is >> involved. >> """ >> >> if (obj1._meta.app_label in self.route_app_labels or >> obj2._meta.app_label == 'julia' or 'redford' >> ): >> return True >> return None >> >> def allow_migrate(self, db, app_label, model_name=None, **hints): >> """ >> Make sure the auth and contenttypes apps only appear in the >> 'auth_db' database. >> """ >> >> >> if db == 'default': >> # Migrate Django core app models if current database is home >> if app_label in ('auth','admin','sessions','contenttypes'): >> return True >> >> else: >> return False >> >> # Non Django core app models should not be migrated if >> database is home >> # Other database should not migrate Django core app models >> >> >> elif app_label in ['auth','admin','sessions','contenttypes']: >> return False >> # Otherwise no opinion, defer to other routers or default database >> return None >> >> >> >> *Redford dbRouter* >> >> >> class RedfordRouter(object): >> >> route_app_labels = ('auth', 'contenttypes', 'sessions', 'admin') >> >> def db_for_read(self, model, **hints): >> if model._meta.app_label == 'redford': >> return 'redford_db' >> return False >> >> def db_for_write(self, model, **hints): >> if model._meta.app_label == 'redford': >> return 'redford_db' >> return False >> >> def allow_relation(self, obj1, obj2, **hints): >> if obj1._meta.app_label == 'redford' or obj2._meta.app_label == >> 'auth': >> return True >> return None >> >> def allow_migrate(self, db, app_label, model_name=None, **hints): >> >> if db == 'default' or app_label in self.route_app_labels: >> print(db, app_label) >> return None >> elif db == 'redford_db': >> if app_label == 'redford': >> return True >> return False >> return None >> >> >> The code for the models is as below : >> >> >> class Employer(models.Model): >> emp_Name = models.OneToOneField(User, on_delete=models.CASCADE, >> null=True) >> emp_Company = models.CharField(max_length=100) >> emp_Address = models.CharField(max_length=500) >> emp_Tel = models.CharField(max_length=100) >> emp_JobTitle = models.CharField(max_length=200, null=True) >> emp_JobDesc = models.CharField(max_length=600, null=False) >> >> def __str__(self): >> return self.emp_Name >> >> >> Hope we can work it out >> >> >> regards >> >> >> [image: --] >> >> Maninder Kumar >> [image: http://]about.me/maninder.s.kumar >> <http://about.me/maninder.s.kumar?promo=email_sig> >> >> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to django-users+unsubscr...@googlegroups.com. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/CABOHK3QsWztSogPx_RzbYcZ46WyK0cHV8JxXBuRSbr2epeQKhg%40mail.gmail.com >> <https://groups.google.com/d/msgid/django-users/CABOHK3QsWztSogPx_RzbYcZ46WyK0cHV8JxXBuRSbr2epeQKhg%40mail.gmail.com?utm_medium=email&utm_source=footer> >> . >> > -- > You received this message because you are subscribed to the Google Groups > "Django users" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to django-users+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/django-users/CAP5HUWpQ0gP50N6R1J6JOwjfQiawFwn4JBsrCVGsBs73SngNeA%40mail.gmail.com > <https://groups.google.com/d/msgid/django-users/CAP5HUWpQ0gP50N6R1J6JOwjfQiawFwn4JBsrCVGsBs73SngNeA%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CABOHK3RBiD6-CeikDzxWYYAjkFtZri3pH9fYS1KrU71vFJewKA%40mail.gmail.com.