Primary/replica configuration, and randomly chooses a replica to read route_app_labels : return db = 'auth_db' return NoneĪnd we also want a router that sends all other apps to the route_app_labels ): 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. route_app_labels : return 'auth_db' return None def allow_relation ( self, obj1, obj2, ** hints ): """ Allow relations if a model in the auth or contenttypes apps is involved. route_app_labels : return 'auth_db' return None def db_for_write ( self, model, ** hints ): """ Attempts to write auth and contenttypes models go to auth_db. """ route_app_labels = def db_for_read ( self, model, ** hints ): """ Attempts to read auth and contenttypes models go to auth_db. Here are the settings specifying theseĬlass AuthRouter : """ A router to control all database operations on models in the auth and contenttypes applications. This one will have several databases: one for theĪuth application, and all other apps using a primary/replica setup So - what does this mean in practice? Let’s consider another sampleĬonfiguration. Interaction of transactions with the database utilization strategy. Query inconsistencies introduced because of the time taken for a The primary/replica (referred to as master/slave by some databases)Ĭonfiguration described is also flawed – itĭoesn’t provide any solution for handling replication lag (i.e., Introduce referential integrity problems that Django can’t Relationships to models outside of the other database. This example won’t work if any of the models in myapp contain Intentionally ignores some complex issues in order to Infrastructure can be used to alter database usage. This example is intended as a demonstration of how the router That router when performing the relevant check. If one of the methods is omitted, Django will skip History, it skips databases where no app is allowed to migrate.Ī router doesn’t have to provide all these methods – it may omit one When makemigrations verifies the migration Changing the behavior of allow_migrate() for models thatĪlready have migrations may result in broken foreign keys, extra tables, Model_name will be silently skipped when running migrate on If allow_migrate() returns False, any migration operations for the Makemigrations always creates migrations for model changes, but This method can also be used to determine the availability of a model on a Note that it may be a historical model, and thus not have any custom attributes, methods, or When model_name is set, hints normally contains the model class Hints are used by certain operations to communicate additional Model._meta.model_name (the lowercased version of the model Model_name is set by most migration operations to the value of The app_label positional argument is the label of the application Shouldn’t run, or None if the router has no opinion. Return True if the operation should run, False if it allow_migrate( db, app_label, model_name = None, ** hints) ¶ĭetermine if the migration operation is allowed to run on the database withĪlias db. Relations within the same database are allowed. Relation should be allowed between two objects. Used by foreign key and many to many operations to determine if a Return True if a relation between obj1 and obj2 should beĪllowed, False if the relation should be prevented, or None if Suggest the database that should be used for writes of objects of Information that might assist in selecting a database, it will be If a database operation is able to provide any additional Suggest the database that should be used for read operations for A database Router is a class that provides up to four methods: db_for_read( model, ** hints) ¶
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |