0

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 :

  • Add a new field (called rundate) which can store the actual date
  • (DateField) Convert all previously entries so they have a populated.

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

Thanks,

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.