@@ -213,7 +213,7 @@ class Address(models.Model):
213
213
index_together_two = models .CharField (max_length = 10 )
214
214
215
215
class Meta :
216
- app_label = "schema "
216
+ app_label = "schema_ "
217
217
index_together = [("index_together_one" , "index_together_two" )]
218
218
219
219
class Author (models .Model ):
@@ -222,14 +222,14 @@ class Author(models.Model):
222
222
index_together_four = models .CharField (max_length = 10 )
223
223
224
224
class Meta :
225
- app_label = "schema "
225
+ app_label = "schema_ "
226
226
index_together = [("index_together_three" , "index_together_four" )]
227
227
228
228
class Book (models .Model ):
229
229
author = EmbeddedModelField (Author )
230
230
231
231
class Meta :
232
- app_label = "schema "
232
+ app_label = "schema_ "
233
233
234
234
with connection .schema_editor () as editor :
235
235
editor .create_model (Book )
@@ -239,20 +239,45 @@ class Meta:
239
239
self .get_constraints_for_columns (
240
240
Book , ["author.address.index_together_one" , "author.address.index_together_two" ]
241
241
),
242
- ["schema_addr_index_t_a0305a_idx " ],
242
+ ["schema__add_index_t_efa93e_idx " ],
243
243
)
244
244
self .assertEqual (
245
245
self .get_constraints_for_columns (
246
246
Book ,
247
247
["author.index_together_three" , "author.index_together_four" ],
248
248
),
249
- ["schema_auth_index_t_65817b_idx " ],
249
+ ["schema__aut_index_t_df32aa_idx " ],
250
250
)
251
- editor .delete_model (Author )
252
- self .assertTableNotExists (Author )
251
+ editor .delete_model (Book )
252
+ self .assertTableNotExists (Book )
253
253
254
+ @isolate_apps ("schema_" )
254
255
def test_unique_together (self ):
255
256
"""Meta.unique_together on an embedded model."""
257
+
258
+ class Address (models .Model ):
259
+ unique_together_one = models .CharField (max_length = 10 )
260
+ unique_together_two = models .CharField (max_length = 10 )
261
+
262
+ class Meta :
263
+ app_label = "schema_"
264
+ unique_together = [("unique_together_one" , "unique_together_two" )]
265
+
266
+ class Author (models .Model ):
267
+ address = EmbeddedModelField (Address )
268
+ unique_together_three = models .CharField (max_length = 10 )
269
+ unique_together_four = models .CharField (max_length = 10 )
270
+
271
+ class Meta :
272
+ app_label = "schema_"
273
+ unique_together = [("unique_together_three" , "unique_together_four" )]
274
+
275
+ class Book (models .Model ):
276
+ author = EmbeddedModelField (Author )
277
+
278
+ class Meta :
279
+ app_label = "schema_"
280
+
256
281
with connection .schema_editor () as editor :
257
282
editor .create_model (Book )
258
283
self .assertTableExists (Book )
@@ -274,31 +299,81 @@ def test_unique_together(self):
274
299
"schema__address_author.address.unique_together_one_author.address.unique_together_two_de682e30_uniq"
275
300
],
276
301
)
277
- editor .delete_model (Author )
278
- self .assertTableNotExists (Author )
302
+ editor .delete_model (Book )
303
+ self .assertTableNotExists (Book )
279
304
305
+ @isolate_apps ("schema_" )
280
306
def test_indexes (self ):
281
307
"""Meta.indexes on an embedded model."""
308
+
309
+ class Address (models .Model ):
310
+ indexed_one = models .CharField (max_length = 10 )
311
+
312
+ class Meta :
313
+ app_label = "schema_"
314
+ indexes = [models .Index (fields = ["indexed_one" ])]
315
+
316
+ class Author (models .Model ):
317
+ address = EmbeddedModelField (Address )
318
+ indexed_two = models .CharField (max_length = 10 )
319
+
320
+ class Meta :
321
+ app_label = "schema_"
322
+ indexes = [models .Index (fields = ["indexed_two" ])]
323
+
324
+ class Book (models .Model ):
325
+ author = EmbeddedModelField (Author )
326
+
327
+ class Meta :
328
+ app_label = "schema_"
329
+
282
330
with connection .schema_editor () as editor :
283
331
editor .create_model (Book )
284
332
self .assertTableExists (Book )
285
333
# Embedded uniques are created.
286
334
self .assertEqual (
287
- self .get_constraints_for_columns (Book , ["author.indexed_by_index_two " ]),
288
- ["schema__aut_indexed_7e3a5c_idx " ],
335
+ self .get_constraints_for_columns (Book , ["author.indexed_two " ]),
336
+ ["schema__aut_indexed_b19137_idx " ],
289
337
)
290
338
self .assertEqual (
291
339
self .get_constraints_for_columns (
292
340
Book ,
293
- ["author.address.indexed_by_index_one " ],
341
+ ["author.address.indexed_one " ],
294
342
),
295
- ["schema__add_indexed_ef5dd6_idx " ],
343
+ ["schema__add_indexed_b64972_idx " ],
296
344
)
297
345
editor .delete_model (Author )
298
346
self .assertTableNotExists (Author )
299
347
348
+ @isolate_apps ("schema_" )
300
349
def test_constraints (self ):
301
350
"""Meta.constraints on an embedded model."""
351
+
352
+ class Address (models .Model ):
353
+ unique_constraint_one = models .CharField (max_length = 10 )
354
+
355
+ class Meta :
356
+ app_label = "schema_"
357
+ constraints = [
358
+ models .UniqueConstraint (fields = ["unique_constraint_one" ], name = "unique_one" )
359
+ ]
360
+
361
+ class Author (models .Model ):
362
+ address = EmbeddedModelField (Address )
363
+ unique_constraint_two = models .CharField (max_length = 10 )
364
+
365
+ class Meta :
366
+ app_label = "schema_"
367
+ constraints = [
368
+ models .UniqueConstraint (fields = ["unique_constraint_two" ], name = "unique_two" )
369
+ ]
370
+
371
+ class Book (models .Model ):
372
+ author = EmbeddedModelField (Author )
373
+
374
+ class Meta :
375
+ app_label = "schema_"
376
+
302
377
with connection .schema_editor () as editor :
303
378
editor .create_model (Book )
304
379
self .assertTableExists (Book )
0 commit comments