Monday, April 23, 2012

Re: How to syncdb programatically (django standalone script) ?

There's a problem in your INSTALLED_APPS setting. You have to use:

('polls',)

Notice the trailing comma. When writing tuples with one item, you must have a traling comma. It indicates that you are writing a tuple, and not simply an expression enclosed in parenthesis. A workaround is to use a list instead, thus ['polls'].

Django will try to iterate INSTALLED_APPS and import all the modules there, in order to do its magic. If you iterate ('polls') you get every character in the string.


Segunda-feira, 15 de Setembro de 2008 22:51:59 UTC+1, Mathieu Leplatre escreveu:
Hi all,

I found many post about specific errors regarding django as a
standalone tool.

With a little bit of researching, I ended up with this script below.
Unfortunately, it fails on database initialization.

...
...
 File "/home/mathieu/Code/uhm/svn/uhm/django/db/backends/sqlite3/
base.py", line 167, in execute
   return Database.Cursor.execute(self, query, params)
   sqlite3.OperationalError: no such table: polls_poll

The sqlite file is empty (0 byte). How can I syncdb programatically
(and only once) ?

Thanks !


import datetime
from django.conf import settings
settings.configure( DATABASE_ENGINE = "sqlite3",
                            DATABASE_NAME   = "./polls.db",
                            INSTALLED_APPS = ('polls'))
from django.db import models

class Poll(models.Model):
    question = models.CharField(max_length=200)
    pub_date = models.DateTimeField('date published')
    class Meta:
        app_label = "polls"

p = Poll(question="What's up?", pub_date=datetime.datetime.now())
p.save()

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

No comments:

Post a Comment