Modify

Ticket #256 (closed defect: fixed)

Opened 5 years ago

Last modified 2 years ago

alter_column on sqlite3 datetime field caused column type to change

Reported by: pmclanahan@… Owned by: andrew
Priority: major Milestone: 0.7
Component: migrations Version: 0.6.1
Keywords: sqlite alter_column Cc:

Description

I altered the default value for a datetime field. The resulting automatic migration contained the following:

# Changing field 'Announcement.pub_date'
# (to signature: django.db.models.fields.DateTimeField())
db.alter_column('areas_announcement', 'pub_date', orm['areas.announcement:pub_date'])

When the migration was run, this was the output:

Running migrations for areas:
 - Migrating forwards to 0003_prefill_html_fields.
 > areas: 0002_add_html_fields
DEBUG - south - south execute "ALTER TABLE "areas_announcement" ADD COLUMN "content_html" text NOT NULL DEFAULT '';" with params "[]"
DEBUG - south - south execute "ALTER TABLE "areas_area" ADD COLUMN "details_html" text NOT NULL DEFAULT '';" with params "[]"
DEBUG - south - south execute "DROP TABLE "areas_announcement";" with params "[]"
DEBUG - south - south execute "ALTER TABLE "areas_announcement_temp" RENAME TO "areas_announcement";" with params "[]"
 > areas: 0003_prefill_html_fields
 - Loading initial data for areas.

After the migration I started seeing errors when trying to edit the announcement models in the admin. Looking at the database I noticed that the "pub_date" column had been changed from a type of "datetime" to a type of "pub_date". Changing the type back manually fixed the issue.

The change I made to the field was from:

pub_date = models.DateTimeField('publication date', blank=True, null=True, editable=False)

to:

pub_date = models.DateTimeField('publication date', default=datetime.datetime.now)

Attachments

Change History

comment:1 Changed 5 years ago by pmclanahan@…

This was seen while using rev ae7db65f1d28.

comment:2 Changed 5 years ago by andrew

  • Status changed from new to assigned

Looks like a problem with our hackish SQLite backend. I'll be rewriting it soon; this should hopefully be fixed when that's done.

comment:3 Changed 5 years ago by pmclanahan@…

No problem. SQLite is just my dev db as you may have guessed. I'm sure the PostgreSQL backend will work fine for deploying to production. I'll let you know if not.

Thanks!

Paul

comment:4 Changed 4 years ago by andrew

  • Milestone changed from 0.6.2 to 0.6.3

comment:5 in reply to: ↑ description Changed 4 years ago by Frank

Just to let you know that I have the exact same problem with a UrlField?, which, after changing the max_length attribute, sets the datatype to 'url' (name of my field) instead of varchar. A quick test made me conclude that this also happen to CharField? fields, I am guessing it's the same for every Field type.

comment:6 Changed 4 years ago by andrew

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

The SQLite backend has now been rewritten and fixed in 0.7, and I can't reproduce this, so closing.

comment:7 Changed 3 years ago by Harry Potter

Can I clone your article to my blog? Thank you…

<a href="http://wmoviesonline.com/harry-potter-and-deathly-hallows-2010-watch-online/ "> watch harry potter and deathly hallows free streaming </a>

comment:8 Changed 3 years ago by Harry Potter

Can I clone your article to my blog? Thank you…

<a href="http://wmoviesonline.com/harry-potter-and-deathly-hallows-2010-watch-online/ "> watch harry potter and deathly hallows free streaming </a>

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.