Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

manage.py syncdb command fails on empty database #3

Open
AndreMiras opened this issue Sep 21, 2013 · 1 comment
Open

manage.py syncdb command fails on empty database #3

AndreMiras opened this issue Sep 21, 2013 · 1 comment

Comments

@AndreMiras
Copy link

I'm running django-vellum==1.4.2 (installed with pip) on both Django 1.4 and Django 1.5.
When I want to syncdb (or run any other manage.py command) from a clean install (empty database), I get an error message:

(mysite) /tmp/mysite/code $ python manage.py syncdb
DatabaseError: no such table: django_site
(mysite) /tmp/mysite/code $

This is on Django Django 1.5.4, but on Django 1.4.1 I get the full stack trace:

(mysite) /tmp/mysite/code $ python manage.py test vellum                                      
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/tmp/mysite/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
    utility.execute()
  File "/tmp/mysite/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/tmp/mysite/lib/python2.7/site-packages/django/core/management/commands/test.py", line 49, in run_from_argv
    super(Command, self).run_from_argv(argv)
  File "/tmp/mysite/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/tmp/mysite/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
    output = self.handle(*args, **options)
  File "/tmp/mysite/lib/python2.7/site-packages/django/core/management/commands/test.py", line 72, in handle
    failures = test_runner.run_tests(test_labels)
  File "/tmp/mysite/lib/python2.7/site-packages/django/test/simple.py", line 380, in run_tests
    suite = self.build_suite(test_labels, extra_tests)
  File "/tmp/mysite/lib/python2.7/site-packages/django/test/simple.py", line 263, in build_suite
    app = get_app(label)
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/loading.py", line 140, in get_app
    self._populate()
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/loading.py", line 64, in _populate
    self.load_app(app_name, True)
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/loading.py", line 88, in load_app
    models = import_module('.models', app_name)
  File "/tmp/mysite/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/tmp/mysite/lib/python2.7/site-packages/vellum/models.py", line 15, in <module>
    from vellum import settings
  File "/tmp/mysite/lib/python2.7/site-packages/vellum/settings.py", line 10, in <module>
    BLOG_NAME = getattr(settings, 'BLOG_NAME', Site.objects.get_current().name)
  File "/tmp/mysite/lib/python2.7/site-packages/django/contrib/sites/models.py", line 25, in get_current
    current_site = self.get(pk=sid)
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/manager.py", line 131, in get
    return self.get_query_set().get(*args, **kwargs)
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/query.py", line 361, in get
    num = len(clone)
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/query.py", line 85, in __len__
    self._result_cache = list(self.iterator())
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/query.py", line 291, in iterator
    for row in compiler.results_iter():
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 763, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 818, in execute_sql
    cursor.execute(sql, params)
  File "/tmp/mysite/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 337, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such table: django_site
(mysite) /tmp/mysite/code $

The funny thing is that I get this message even with the BLOG_NAME setting setup. So it means the default value of the expression getattr(settings, 'BLOG_NAME', Site.objects.get_current().name) allways gets evaluated :S
Replacing the getattr by a try/except (ValueError) clause should solve the issue.

@AndreMiras
Copy link
Author

My settings.py and requirements.txt files for reproducing the issue.
https://gist.github.com/AndreMiras/6652284#file-settings-py
https://gist.github.com/AndreMiras/6652271#file-requirements-txt

AndreMiras added a commit to AndreMiras/django-vellum that referenced this issue Sep 21, 2013
Fixes "DatabaseError: no such table: django_site" issue, refs pigmonkey#3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant