@@ -48,6 +48,64 @@ DATABASES = {
48
48
` OPTIONS ` is an optional dictionary of parameters that will be passed to
49
49
[ ` MongoClient ` ] ( https://pymongo.readthedocs.io/en/stable/api/pymongo/mongo_client.html ) .
50
50
51
+ In your Django settings, you must specify that all models should use
52
+ ` MongoAutoField ` .
53
+
54
+ ``` python
55
+ DEFAULT_AUTO_FIELD = " django_mongodb.fields.MongoAutoField"
56
+ ```
57
+
58
+ This won't override any apps that have an ` AppConfig ` that specifies
59
+ ` default_auto_field ` . For those apps, you'll need to create a custom
60
+ ` AppConfig ` .
61
+
62
+ For example, you might create ` mysite/apps.py ` like this:
63
+
64
+ ``` python
65
+ from django.contrib.admin.apps import AdminConfig
66
+ from django.contrib.auth.apps import AuthConfig
67
+ from django.contrib.contenttypes.apps import ContentTypesConfig
68
+
69
+
70
+ class MongoAdminConfig (AdminConfig ):
71
+ default_auto_field = " django_mongodb.fields.MongoAutoField"
72
+
73
+
74
+ class MongoAuthConfig (AuthConfig ):
75
+ default_auto_field = " django_mongodb.fields.MongoAutoField"
76
+
77
+
78
+ class MongoContentTypesConfig (ContentTypesConfig ):
79
+ default_auto_field = " django_mongodb.fields.MongoAutoField"
80
+ ```
81
+
82
+ Then replace each app reference in the ` INSTALLED_APPS ` setting with the new
83
+ `` AppConfig `` . For example, replace ` 'django.contrib.admin' ` with
84
+ ` 'mysite.apps.MongoAdminConfig' ` .
85
+
86
+ Because all models must use ` MongoAutoField ` , each third-party and contrib app
87
+ you use needs to have its own migrations specific to MongoDB.
88
+
89
+ For example, you might configure your settings like this:
90
+
91
+ ``` python
92
+ MIGRATION_MODULES = {
93
+ " admin" : " mongo_migrations.admin" ,
94
+ " auth" : " mongo_migrations.auth" ,
95
+ " contenttypes" : " mongo_migrations.contenttypes" ,
96
+ }
97
+ ```
98
+
99
+ After creating a ` mongo_migrations ` directory, you can then run:
100
+
101
+ ``` console
102
+ $ python manage.py makemigrations admin auth contenttypes
103
+ Migrations for 'admin':
104
+ mongo_migrations/admin/0001_initial.py
105
+ - Create model LogEntry
106
+ ...
107
+ ```
108
+
51
109
## Known issues and limitations
52
110
53
111
- The following ` QuerySet ` methods aren't supported:
0 commit comments