File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -174,3 +174,41 @@ class Meta:
174174 ):
175175 with connection .schema_editor () as schema_editor :
176176 schema_editor .table_sql (MetaOptions )
177+
178+
179+ def test_model_id ():
180+ """
181+ Tests the auto-generated id added by Django.
182+
183+ """
184+
185+ class SomeModel (CrateModel ):
186+ class Meta :
187+ app_label = "ignore"
188+
189+ assert SomeModel ._meta .get_field ("id" )
190+ assert len (SomeModel ._meta .fields ) == 1
191+
192+ with connection .schema_editor () as schema_editor :
193+ sql , params = schema_editor .column_sql (
194+ SomeModel , SomeModel ._meta .get_field ("id" )
195+ )
196+ assert (
197+ sql
198+ == "INTEGER GENERATED ALWAYS AS CAST((random() * 1.0E9) AS integer) NOT NULL PRIMARY KEY"
199+ )
200+
201+ class SomeModel (CrateModel ):
202+ id = models .TextField (primary_key = True )
203+
204+ class Meta :
205+ app_label = "ignore"
206+
207+ assert SomeModel ._meta .get_field ("id" )
208+ assert len (SomeModel ._meta .fields ) == 1
209+
210+ with connection .schema_editor () as schema_editor :
211+ sql , params = schema_editor .column_sql (
212+ SomeModel , SomeModel ._meta .get_field ("id" )
213+ )
214+ assert sql == "text NOT NULL PRIMARY KEY"
You can’t perform that action at this time.
0 commit comments