That is a short-coming of the Django ORM, unfortunately solving the
problem of iterative schema changes is pretty difficult.

There are some projects around that attempt to fix this issue, in
varying stages of completion:
http://south.aeracode.org/wiki/Alternatives is a decent list.

As for your specific question of changing the column name - eep :)
It's slightly tedious to do that sort of thing seamlessly with the
stock ORM.

Here's the workflow I'd suggest for changing a column name:

1) Manually create a column named after what you want the new name to
be, with the same data type, following the Django ORM's naming scheme
2) Copy the data from the old column for all rows into the newly created column
3) Update the code and change the property name in the model code
4) Ensure the application seems to be working
5) Drop the old-named column

Note: These instructions may not apply directly, depending on what
your property is - in the case of a many-to-many relationship, for
example, a join table is used. I'm sure you can figure out how to go
from here, though.

-Chris

On Thu, Sep 10, 2009 at 1:31 PM, Thomas <thomas.e.rectenw...@gmail.com> wrote:
>
> I've been teaching myself Django over the past couple of days.  Thus
> far, everything has been going smoothly, as I typically do a lot of
> non-web based Python coding, so am familiar with the language.
> However, Django's DB API is my first look into ORM and how it works.
>
> I understand the basics; how to create models and run a syncdb to
> generate tables.  I understand how to query, update/insert, etc. the
> data by instantiating the class model and using the API methods
> against it.  All nice and well.
>
> Where I get lost fast is when I need to make changes to a table.  For
> example, say I want to change the name of a column from 'foo' to
> 'bar'.  I can run an ALTER TABLE in SQL and do this easily, but I
> thought the idea of ORM was that you weren't supposed to be using SQL
> directly.  I.e. is there a way to change a column name (or a table
> name, or a attribute type, etc.) from within ORM, i.e. from within the
> model class; or do I have to run the SQL, then change the model to
> 'match' that SQL, and then run a syncdb.
>
> I love the concept of being able to access data through objects, but
> am just confused as what 'workflow' I should be following when doing
> something like changing a column name.
>
> Sorry for the basic question.  Google hasn't been much help when
> getting into these details.  I can sort of 'figure it out' by running
> the SQL, matching the model class and going from there... but wasn't
> sure if that was the best, or only way.
>
> Thanks,
> Thomas
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to