The best way to populate sqlite3 database

6 views
Skip to first unread message

Zeynel

unread,
Dec 12, 2009, 12:01:58 PM12/12/09
to Django users
Hi,

I first put the data in csv format than convert it to json and then
create a fixture... which seems a long process. This
http://stackoverflow.com/questions/1884694/how-to-populate-sqlite3-in-django/1885417#1885417
answer suggests to "Just load the database directly," but without
giving much practical info. Can anyone here help?

Shawn Milochik

unread,
Dec 12, 2009, 3:04:11 PM12/12/09
to django...@googlegroups.com
The fastest way for large files is to use sqlite3's .import command to directly import a file. However, this will bypass any validation done by your models. You could end up with "bad" data, in that it doesn't conform to the rules of your models.

Or, you can just write an external script to read the file and create model instances. Here's a brief example:


Shawn

Zeynel

unread,
Dec 12, 2009, 4:33:27 PM12/12/09
to Django users
On Dec 12, 3:04 pm, Shawn Milochik <sh...@milochik.com> wrote:

>
> http://pastebin.com/f651cf8de

Hi,

Thanks for the script, I want to use it but I have some questions.
These are from the previous thread: http://groups.google.com/group/django-users/msg/091f964c6c8e40c7

but I have others as well.

Thanks again.
Reply all
Reply to author
Forward
0 new messages