mirror of
https://github.com/django/django.git
synced 2025-08-04 02:48:35 +00:00
Fixed #21692 -- Quote table name when creating it.
This commit is contained in:
parent
efddae252c
commit
3efd1b8b93
3 changed files with 40 additions and 3 deletions
|
@ -3,13 +3,13 @@ import datetime
|
|||
import unittest
|
||||
|
||||
from django.test import TransactionTestCase
|
||||
from django.db import connection, DatabaseError, IntegrityError
|
||||
from django.db import connection, DatabaseError, IntegrityError, OperationalError
|
||||
from django.db.models.fields import IntegerField, TextField, CharField, SlugField
|
||||
from django.db.models.fields.related import ManyToManyField, ForeignKey
|
||||
from django.db.transaction import atomic
|
||||
from .models import (Author, AuthorWithM2M, Book, BookWithLongName,
|
||||
BookWithSlug, BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename,
|
||||
UniqueTest)
|
||||
UniqueTest, Thing)
|
||||
|
||||
|
||||
class SchemaTests(TransactionTestCase):
|
||||
|
@ -26,6 +26,7 @@ class SchemaTests(TransactionTestCase):
|
|||
models = [
|
||||
Author, AuthorWithM2M, Book, BookWithLongName, BookWithSlug,
|
||||
BookWithM2M, Tag, TagIndexed, TagM2MTest, TagUniqueRename, UniqueTest,
|
||||
Thing
|
||||
]
|
||||
|
||||
# Utility functions
|
||||
|
@ -683,3 +684,26 @@ class SchemaTests(TransactionTestCase):
|
|||
column_name,
|
||||
connection.introspection.get_indexes(connection.cursor(), BookWithLongName._meta.db_table),
|
||||
)
|
||||
|
||||
def test_creation_deletion_reserved_names(self):
|
||||
"""
|
||||
Tries creating a model's table, and then deleting it when it has a
|
||||
SQL reserved name.
|
||||
"""
|
||||
# Create the table
|
||||
with connection.schema_editor() as editor:
|
||||
try:
|
||||
editor.create_model(Thing)
|
||||
except OperationalError as e:
|
||||
self.fail("Errors when applying initial migration for a model "
|
||||
"with a table named after a SQL reserved word: %s" % e)
|
||||
# Check that it's there
|
||||
list(Thing.objects.all())
|
||||
# Clean up that table
|
||||
with connection.schema_editor() as editor:
|
||||
editor.delete_model(Thing)
|
||||
# Check that it's gone
|
||||
self.assertRaises(
|
||||
DatabaseError,
|
||||
lambda: list(Thing.objects.all()),
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue