Django

Code

Changeset 7789

Show
Ignore:
Timestamp:
06/29/08 19:38:14 (2 months ago)
Author:
mtredinnick
Message:

Fixed #7565 -- Fixed a problem with PostgreSQL sequence resetting in loaddata.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/postgresql/operations.py

    r7477 r7789  
    9898            # or 1 if there are none. Set the `is_called` property (the third argument to `setval`) to true 
    9999            # if there are records (as the max pk value is already in use), otherwise set it to false. 
    100             for f in model._meta.fields: 
     100            for f in model._meta.local_fields: 
    101101                if isinstance(f, models.AutoField): 
    102102                    output.append("%s setval('%s', coalesce(max(%s), 1), max(%s) %s null) %s %s;" % \ 
  • django/trunk/tests/regressiontests/fixtures_regress/models.py

    r7595 r7789  
    2121    name = models.CharField(max_length=20, null=True) 
    2222    owner = models.ForeignKey(User, null=True) 
    23      
     23 
    2424    def __unicode__(self): 
    2525        # Oracle doesn't distinguish between None and the empty string. 
     
    3939        Absolute.load_count += 1 
    4040 
     41class Parent(models.Model): 
     42    name = models.CharField(max_length=10) 
     43 
     44class Child(Parent): 
     45    data = models.CharField(max_length=10) 
     46 
    4147 
    4248__test__ = {'API_TESTS':""" 
     
    4551# Load a fixture that uses PK=1 
    4652>>> management.call_command('loaddata', 'sequence', verbosity=0) 
    47          
     53 
    4854# Create a new animal. Without a sequence reset, this new object 
    4955# will take a PK of 1 (on Postgres), and the save will fail. 
     
    6268 
    6369############################################### 
    64 # Regression test for ticket #6436 --  
     70# Regression test for ticket #6436 -- 
    6571# os.path.join will throw away the initial parts of a path if it encounters 
    66 # an absolute path. This means that if a fixture is specified as an absolute path,  
     72# an absolute path. This means that if a fixture is specified as an absolute path, 
    6773# we need to make sure we don't discover the absolute path in every fixture directory. 
    6874 
     
    95101>>> sys.stderr = savestderr 
    96102 
     103############################################### 
     104# Test for ticket #7565 -- PostgreSQL sequence resetting checks shouldn't 
     105# ascend to parent models when inheritance is used (since they are treated 
     106# individually). 
     107 
     108>>> management.call_command('loaddata', 'model-inheritance.json', verbosity=0) 
     109 
    97110"""}