Modify

Ticket #317 (closed defect: fixed)

Opened 4 years ago

Last modified 17 months ago

Migration fails for PostgreSQL if default value contains percentage signs (%)

Reported by: DrMeers@… Owned by: andrew
Priority: major Milestone: 0.7
Component: commands Version: 0.6.2
Keywords: postgres Cc: DrMeers@…

Description

Tried migrating a model with the following field:

    date_format = models.CharField(max_length=255, default='%d-%b-%y')

Got:

File "/.../django/db/backends/util.py", line 19, in execute
    return self.cursor.execute(sql, params)
IndexError: list index out of range

Offending value of sql was:

CREATE TABLE "tracker_csvformat" ("id" serial NOT NULL PRIMARY KEY, "format" varchar(1024) NOT NULL, "date_format" varchar(255) NOT NULL DEFAULT '%d-%b-%y');

Related to ticket #77.

Attachments

Change History

comment:1 Changed 4 years ago by DrMeers@…

Actually it looks like it is not postgres-specific -- just the fact that cursor.execute wanted to do sql % params. Replacing 'default': "'%d-%b-%y' with 'default': "'%%d-%%b-%%y' in the generated migration file solved the problem.

comment:2 Changed 4 years ago by andrew

  • Status changed from new to closed
  • Resolution set to fixed
  • Milestone set to 0.7

Fixed in [6213146f0f06].

comment:3 Changed 18 months ago by Michel van Leeuwen <michel@…>

I still have this problem.
see: http://stackoverflow.com/questions/12442768

The problem is not in the migration while adding a field with percentage, but in any migration after this migration in the same table.
In recreating the table, see: http://stackoverflow.com/questions/12442768 or this stacktrace:

 File "/media/storage/django/sites/palmrif/eggs/South-0.7.6-py2.7.egg/south/db/sqlite3.py", line 31, in add_column
    field.column: self._column_sql_for_create(table_name, name, field, False),
  File "/media/storage/django/sites/palmrif/eggs/South-0.7.6-py2.7.egg/south/db/generic.py", line 44, in _cache_clear
    return func(self, table, *args, **opts)
  File "/media/storage/django/sites/palmrif/eggs/South-0.7.6-py2.7.egg/south/db/sqlite3.py", line 103, in _remake_table
    ", ".join(["%s %s" % (self.quote_name(cname), ctype) for cname, ctype in definitions.items()]),

comment:4 Changed 17 months ago by mrooney.south@…

I filed http://south.aeracode.org/ticket/1192 for a new bug to track this.

View

Add a comment

Modify Ticket

Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.