Fixed #7565 -- Fixed a problem with PostgreSQL sequence resetting in loaddata.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@7789 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f62e5a1fba
commit
b0bc8b9dfd
|
@ -97,7 +97,7 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
# Use `coalesce` to set the sequence for each model to the max pk value if there are records,
|
# Use `coalesce` to set the sequence for each model to the max pk value if there are records,
|
||||||
# or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true
|
# or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true
|
||||||
# if there are records (as the max pk value is already in use), otherwise set it to false.
|
# if there are records (as the max pk value is already in use), otherwise set it to false.
|
||||||
for f in model._meta.fields:
|
for f in model._meta.local_fields:
|
||||||
if isinstance(f, models.AutoField):
|
if isinstance(f, models.AutoField):
|
||||||
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \
|
||||||
(style.SQL_KEYWORD('SELECT'),
|
(style.SQL_KEYWORD('SELECT'),
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[
|
||||||
|
{"pk": 1, "model": "fixtures_regress.parent", "fields": {"name": "fred"}},
|
||||||
|
{"pk": 1, "model": "fixtures_regress.child", "fields": {"data": "apple"}}
|
||||||
|
]
|
|
@ -38,6 +38,12 @@ class Absolute(models.Model):
|
||||||
super(Absolute, self).__init__(*args, **kwargs)
|
super(Absolute, self).__init__(*args, **kwargs)
|
||||||
Absolute.load_count += 1
|
Absolute.load_count += 1
|
||||||
|
|
||||||
|
class Parent(models.Model):
|
||||||
|
name = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
class Child(Parent):
|
||||||
|
data = models.CharField(max_length=10)
|
||||||
|
|
||||||
|
|
||||||
__test__ = {'API_TESTS':"""
|
__test__ = {'API_TESTS':"""
|
||||||
>>> from django.core import management
|
>>> from django.core import management
|
||||||
|
@ -94,4 +100,11 @@ No fixture data found for 'bad_fixture2'. (File format may be invalid.)
|
||||||
|
|
||||||
>>> sys.stderr = savestderr
|
>>> sys.stderr = savestderr
|
||||||
|
|
||||||
|
###############################################
|
||||||
|
# Test for ticket #7565 -- PostgreSQL sequence resetting checks shouldn't
|
||||||
|
# ascend to parent models when inheritance is used (since they are treated
|
||||||
|
# individually).
|
||||||
|
|
||||||
|
>>> management.call_command('loaddata', 'model-inheritance.json', verbosity=0)
|
||||||
|
|
||||||
"""}
|
"""}
|
||||||
|
|
Loading…
Reference in New Issue