Easy way to add tables to existing database?

1 view
Skip to first unread message

jocknerd

unread,
Sep 22, 2005, 1:25:22 PM9/22/05
to Django users
What's the easiest way to add a table to an existing database. I'm
currently destroying the database and recreating it but this will be a
problem once I've got real data. I was thinking about doing this:

Make the change to the model and then run django-admin.py sql
myproject. I'm using PostgreSQL so I type psql databasename and then
create the new table with the sql code for the new table that was
generated previously. Then I restart the django server.

Would that work? Is there an easier way?


I really like how Ruby on Rails does it. You add the table to the
database and its automatically added to your website.

Adrian Holovaty

unread,
Sep 22, 2005, 5:39:14 PM9/22/05
to django...@googlegroups.com
On 9/22/05, jocknerd <jeff...@gmail.com> wrote:
> What's the easiest way to add a table to an existing database. I'm
> currently destroying the database and recreating it but this will be a
> problem once I've got real data. I was thinking about doing this:
>
> Make the change to the model and then run django-admin.py sql
> myproject. I'm using PostgreSQL so I type psql databasename and then
> create the new table with the sql code for the new table that was
> generated previously. Then I restart the django server.

Yup, doing it with manual SQL statements, as you've outlined, is the
best way to do it at this point. It's a tricky problem to solve, but a
couple of people are working on a more automated solution.

Adrian

--
Adrian Holovaty
holovaty.com | djangoproject.com | chicagocrime.org

Kenneth Gonsalves

unread,
Sep 22, 2005, 9:54:33 PM9/22/05
to django...@googlegroups.com
On Thursday 22 Sep 2005 10:55 pm, jocknerd wrote:
> Make the change to the model and then run django-admin.py sql
> myproject.  I'm using PostgreSQL so I type psql databasename and then
> create the new table with the sql code for the new table that was
> generated previously.  Then I restart the django server.
>
> Would that work?  Is there an easier way?

this works - but you have to run django-admin.py sqlall, otherwise you
wont get the additonal inserts/creates that django makes for every new
table. Since every new table has 5 create/insert statements, it is
fairly trivial to write them on ones one if one wants. I personaly just
run sqlall and cut an paste the new code

--
regards
kg

http://www.livejournal.com/users/lawgon
tally ho! http://avsap.org.in
ಇಂಡ್ಲಿನಕ್ಸ வாழ்க!
Reply all
Reply to author
Forward
0 new messages