mirror of https://github.com/django/django.git
Fixed #27096 -- Fixed primary key introspection for sqlite3 backend
This commit is contained in:
parent
9f27735612
commit
00bb47b58f
|
@ -214,7 +214,7 @@ class DatabaseIntrospection(BaseDatabaseIntrospection):
|
||||||
results = results[results.index('(') + 1:results.rindex(')')]
|
results = results[results.index('(') + 1:results.rindex(')')]
|
||||||
for field_desc in results.split(','):
|
for field_desc in results.split(','):
|
||||||
field_desc = field_desc.strip()
|
field_desc = field_desc.strip()
|
||||||
m = re.search('"(.*)".*PRIMARY KEY( AUTOINCREMENT)?$', field_desc)
|
m = re.search('"(.*)".*PRIMARY KEY( AUTOINCREMENT)?', field_desc)
|
||||||
if m:
|
if m:
|
||||||
return m.groups()[0]
|
return m.groups()[0]
|
||||||
return None
|
return None
|
||||||
|
|
|
@ -15,7 +15,7 @@ class City(models.Model):
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class District(models.Model):
|
class District(models.Model):
|
||||||
city = models.ForeignKey(City, models.CASCADE)
|
city = models.ForeignKey(City, models.CASCADE, primary_key=True)
|
||||||
name = models.CharField(max_length=50)
|
name = models.CharField(max_length=50)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
|
@ -6,7 +6,7 @@ from django.db import connection
|
||||||
from django.db.utils import DatabaseError
|
from django.db.utils import DatabaseError
|
||||||
from django.test import TransactionTestCase, mock, skipUnlessDBFeature
|
from django.test import TransactionTestCase, mock, skipUnlessDBFeature
|
||||||
|
|
||||||
from .models import Article, ArticleReporter, City, Reporter
|
from .models import Article, ArticleReporter, City, District, Reporter
|
||||||
|
|
||||||
|
|
||||||
class IntrospectionTests(TransactionTestCase):
|
class IntrospectionTests(TransactionTestCase):
|
||||||
|
@ -165,7 +165,9 @@ class IntrospectionTests(TransactionTestCase):
|
||||||
def test_get_primary_key_column(self):
|
def test_get_primary_key_column(self):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
primary_key_column = connection.introspection.get_primary_key_column(cursor, Article._meta.db_table)
|
primary_key_column = connection.introspection.get_primary_key_column(cursor, Article._meta.db_table)
|
||||||
|
pk_fk_column = connection.introspection.get_primary_key_column(cursor, District._meta.db_table)
|
||||||
self.assertEqual(primary_key_column, 'id')
|
self.assertEqual(primary_key_column, 'id')
|
||||||
|
self.assertEqual(pk_fk_column, 'city_id')
|
||||||
|
|
||||||
def test_get_indexes(self):
|
def test_get_indexes(self):
|
||||||
with connection.cursor() as cursor:
|
with connection.cursor() as cursor:
|
||||||
|
|
Loading…
Reference in New Issue