Ticket #266 (closed defect: fixed)

Opened 6 years ago

Last modified 6 years ago

rename_column does not specify table name

Reported by: anonymous Owned by: andrew
Priority: major Milestone: 0.7
Component: commands Version: 0.6
Keywords: Cc:


I renamed a model field from a foreign key to a varchar using:

./manage.py startmigration <app> change_field --auto

When running the migration with:

./manage.py migrate <app>

I got the following error:

db.alter_column('greek_letter', ormfrat.lineentity:greek_letter?)

TypeError?: alter_column() takes at least 4 arguments (3 given)

Going into the migration and adding the table name as the first argument fixes the problem.

When running the migration backwards, I get the following error:

psycopg2.ProgrammingError?: column "greek_letter" cannot be cast to type "pg_catalog.int4"

In order to do the reverse migration I delete the column and create a new one altogether.

I am running south against PostgresSQL using psycopg2.

Change History

comment:1 Changed 6 years ago by andrew

  • Status changed from new to assigned
  • Milestone set to 0.6.2

This is very odd; is there any chance of seeing the before/after models which caused this? Does it happen again if you try in the same situation?

Also, the error you get on backwards() is because you altered an integer column to a text one (most likely), which postgres considers an irreversible operation.

comment:2 Changed 6 years ago by andrew

  • Milestone changed from 0.6.2 to 0.6.3

comment:3 Changed 6 years ago by preston@…

Just a note that I hit this bug too.

Went from a varchar to a FK column

--auto didn't generate a table name:

# Renaming column for field 'country'.
db.rename_column('country', 'country_id')

comment:4 Changed 6 years ago by flashingpumpkin@…

I've gotta second that. Went from varchar to ForeignKey? too and got the same hiccup.

The db backend used is MySQL

(pp)alen@fp:[pp]$ python manage.py startmigration pa profile --auto
 + Added model 'pa.referrercode'
 ~ Changed field 'pa.profile.referrer_code'.
Created 0005_profile.py.

(pp)alen@fp:[pp]$ python manage.py migrate pa
Running migrations for pa:
 - Migrating forwards to 0005_profile.
 > pa: 0005_profile
Traceback (most recent call last):
  File "/home/alen/projects/pp/lib/python2.6/site-packages/south/migration.py", line 307, in run_migrations
  File "/home/alen/projects/pp/src/pa/pa/migrations/0005_profile.py", line 18, in forwards
    db.rename_column('referrer_code', 'referrer_code_id')
TypeError: rename_column() takes exactly 4 arguments (3 given)
 ! Error found during dry run of migration! Aborting.

comment:5 Changed 6 years ago by andrew

Could one of you post the models.py file that's making this happen? (pref. before and after), and the migration?

comment:6 Changed 6 years ago by anonymous

Andrew - I was just able to reproduce this with a copy of my code.

The change was going from line 11 (commented out) to line 12 in this paste:

The Country class is coming from django-countries


comment:7 Changed 6 years ago by anonymous

The models.py and the pre and post FK change migrations from my test:



comment:8 Changed 6 years ago by ed@…

My situtation was going from a PositiveSmallIntegerField? to a FK. Same symptoms.

comment:9 Changed 6 years ago by epottercg@…

Any progress on this?

comment:10 Changed 6 years ago by andrew

  • Status changed from assigned to closed
  • Resolution set to fixed
  • Milestone changed from 0.6.3 to 0.7

Fixed in 0.7.

Note: See TracTickets for help on using tickets.