python - Django syncdb error -


i have django.contrib.auth in installed apps , was working 10 minutes ago. deleted existed database because had problems south migrations. when try rebuild error.

error: django.db.utils.databaseerror: no such table: auth_user

traceback (most recent call last):   file "manage.py", line 11, in <module>     execute_manager(settings)   file "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 438, in execute_manager     utility.execute()   file "/usr/lib/python2.7/site-packages/django/core/management/__init__.py", line 379, in execute     self.fetch_command(subcommand).run_from_argv(self.argv)   file "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 191, in run_from_argv     self.execute(*args, **options.__dict__)   file "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 219, in execute     self.validate()   file "/usr/lib/python2.7/site-packages/django/core/management/base.py", line 249, in validate     num_errors = get_validation_errors(s, app)   file "/usr/lib/python2.7/site-packages/django/core/management/validation.py", line 35, in get_validation_errors     (app_name, error) in get_app_errors().items():   file "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 146, in get_app_errors     self._populate()   file "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 61, in _populate     self.load_app(app_name, true)   file "/usr/lib/python2.7/site-packages/django/db/models/loading.py", line 78, in load_app     models = import_module('.models', app_name)   file "/usr/lib/python2.7/site-packages/django/utils/importlib.py", line 35, in import_module     __import__(name)   file "/home/bruk/workspace/hungrydroid/src/hungrydroid/ingredient/models.py", line 22, in <module>     class ingredient(models.model):   file "/home/bruk/workspace/hungrydroid/src/hungrydroid/ingredient/models.py", line 26, in ingredient     fkowner = models.foreignkey(user, default=user.objects.get(pk=1).id)   file "/usr/lib/python2.7/site-packages/django/db/models/manager.py", line 132, in     return self.get_query_set().get(*args, **kwargs)   file "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 342, in     num = len(clone)   file "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 80, in __len__     self._result_cache = list(self.iterator())   file "/usr/lib/python2.7/site-packages/django/db/models/query.py", line 271, in iterator     row in compiler.results_iter():   file "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 677, in results_iter     rows in self.execute_sql(multi):   file "/usr/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 732, in execute_sql     cursor.execute(sql, params)   file "/usr/lib/python2.7/site-packages/django/db/backends/util.py", line 15, in execute     return self.cursor.execute(sql, params)   file "/usr/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 200, in execute     return database.cursor.execute(self, query, params) **django.db.utils.databaseerror: no such table: auth_user** 

the problem running query against user model

  file "/home/bruk/workspace/hungrydroid/src/hungrydroid/ingredient/models.py", line 26, in ingredient fkowner = models.foreignkey(user, default=user.objects.get(pk=1).id) 

in syncdb process (during field declaration actually, time module imported, during validation process).

this make sure auth_user query executed before auth_user table created.

a safer way functionality default user do

def get_default_user():     return user.objects.get(pk=1) 

and in field declaration, do

fkowner = models.foreignkey(user, default=get_default_user) 

as per model field reference default can callable. note have same problem if used get_default_user() in there - executes immediately, not on-demand.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -