On 18 oct, 23:15, Mike Ramirez <[email protected]> wrote:
> On Sunday 18 October 2009 13:57:58 Shakefu wrote:
>
> > > > a first working implementation of my models (remember you can test
> > > > your models from the interactive shell and/or python scripts).
>
> > > Or write unit tests, which are more suited for testing than loose
> > > bunch of scripts
>
> > Well, I certainly have noticed that a lot of guides/tutorials/snippets
> > start with models and then write the rest of the required code in
> > varying order.
>
> > Is there any downside to starting with the models first?
>
> The biggest one is that if you decide later to add a field to the model that
> isn't there and you've filled in some data to the db.
I wouldn't call this a "downside". It's a very common situation when
programming db-backed applications, and you'll very certainly face it
whether you start with the models or not.
> Syncdb is ineffective at
> updating the table so you either drop the table and reload the data as a
> fixture with the added field data, or start again with data or use a db
> migration tool like django evolution.
Or write a custom migration script, or just fire your favorite db
client and issue a couple SQL queries.
> I tend to start with the models first and when I add a field, I just use alter
> to update the table in place. This has a gotcha with NOT NULL though, if you
> don't specify a default you'll end up with an error. To bypass this error, I
> usually don't add the NOT NULL constraint till after I've added the field and
> updated the existing rows with the required data.
>
> This may not be the best approach to it, but it works for me and is fast
> enough and requires less prep time for using such tools as evolution and the
> like (no need to install or learn them) and/or editting fixtures.
+1
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---