felix001
felix001

Reputation: 16691

MySQL Table Changes in Django

I've inherited an app in Django (v1.5) that uses MySQL as the backend. Unfortantly the way that the date is recorded within the table doesnt lend itself well to sorting by date. i.e

+------------+--------------+------+-----+---------+----------------+
| Field      | Type         | Null | Key | Default | Extra          |
+------------+--------------+------+-----+---------+----------------+
| id         | int(11)      | NO   | PRI | NULL    | auto_increment |
| datey      | int(11)      | NO   |     | NULL    |                |
| datem      | int(11)      | NO   |     | NULL    |                |
| dated      | int(11)      | NO   |     | NULL    |                |
| dateh      | int(11)      | NO   |     | NULL    |                |
| datemin    | int(11)      | NO   |     | NULL    |                |
| dates      | int(11)      | NO   |     | NULL    |                |
| detail     | varchar(45)  | NO   |     | NULL    |                |
+------------+--------------+------+-----+---------+----------------+

Based on this model structure. I need to :

What is best or recommended method to do this without losing all of my previous data ?

Thanks,

Upvotes: 0

Views: 39

Answers (1)

Michael Plakhov
Michael Plakhov

Reputation: 2291

You can add migrations (with South) in which you will

  • add new data field (with schemamigration)
  • make a data migration which will process all records, convert old data, write to new field
  • Optional: add schemamigration to remove old field

Upvotes: 2

Related Questions