Forums

syncdb error

I changed the attribute of one of my model fields and git-pulled the update. After the update, this error appeared every time I tried to access the database from my website:

OperationalError at /admin/blog/post/
no such column: blog_post.Day
Request Method: GET
Request URL:    http://cqcum6er.pythonanywhere.com/admin/blog/post/
Django Version: 1.8.2
Exception Type: OperationalError
Exception Value:    no such column: blog_post.Day
Exception Location: /home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 318
Python Executable:  /usr/local/bin/uwsgi
Python Version: 2.7.6
Python Path:    ['/var/www',
 '.',
 '',
 '/var/www',
 '/home/cqcum6er/my-first-blog/myvenv/lib/python2.7',
 '/home/cqcum6er/my-first-blog/myvenv/lib/python2.7/plat-x86_64-linux-gnu',
 '/home/cqcum6er/my-first-blog/myvenv/lib/python2.7/lib-tk',
 '/home/cqcum6er/my-first-blog/myvenv/lib/python2.7/lib-old',
 '/home/cqcum6er/my-first-blog/myvenv/lib/python2.7/lib-dynload',
 '/usr/lib/python2.7',
 '/usr/lib/python2.7/plat-x86_64-linux-gnu',
 '/usr/lib/python2.7/lib-tk',
 '/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages',
 '/home/cqcum6er/my-first-blog/myvenv/lib/python2.7/site-packages',
 '/home/cqcum6er/my-first-blog']
Server time:    Fri, 25 Nov 2016 19:46:45 +0000

I ran the syncdb command, but the following error showed up:

23:02 ~/my-first-blog (master)$ python manage.py syncdb                                                
Creating tables ...
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 429, in execut
e_from_command_line
    utility.execute()
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/__init__.py", line 379, in execut
e
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 191, in run_from_a
rgv
    self.execute(*args, **options.__dict__)
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 220, in execute
    output = self.handle(*args, **options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/base.py", line 351, in handle
    return self.handle_noargs(**options)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/commands/syncdb.py", line 109, in handle_noargs
    emit_post_sync_signal(created_models, verbosity, interactive, db)
  File "/usr/local/lib/python2.7/dist-packages/django/core/management/sql.py", line 190, in emit_post_sync_signal
    interactive=interactive, db=db)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 172, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/auth/management/__init__.py", line 30, in create_permissions
    ctype = ContentType.objects.get_for_model(klass)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/contenttypes/models.py", line 38, in get_for_model
    defaults = {'name': smart_unicode(opts.verbose_name_raw)},
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/manager.py", line 135, in get_or_create
    return self.get_query_set().get_or_create(**kwargs)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 378, in get_or_create
    return self.get(**lookup), False
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 344, in get
    num = len(clone)
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 82, in __len__
    self._result_cache = list(self.iterator())
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/query.py", line 273, in iterator
    for row in compiler.results_iter():
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 680, in results_iter
    for rows in self.execute_sql(MULTI):
  File "/usr/local/lib/python2.7/dist-packages/django/db/models/sql/compiler.py", line 735, in execute_sql
    cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/util.py", line 34, in execute
    return self.cursor.execute(sql, params)
  File "/usr/local/lib/python2.7/dist-packages/django/db/backends/sqlite3/base.py", line 234, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.DatabaseError: no such column: django_content_type.name

Does anyone know how to correct this? I ran my project locally , and it ran without a problem. Nothing besides models.py and views.py were modified for my update.

It looks like your web app uses a virtualenv. Did you activate that virtualenv before you ran the syncdb?

It wasn't activated; from the manage.py directory:

18:08 ~/my-first-blog (master)$ which python
/usr/bin/python

How can I resolve this conflict?

You can start a console with the virtualenv activated from the web app's tab.

Thank you glenn, I executed the syncdb command under virtualenv console. The error is gone, but now there are just blanks where the data should be on the web page. The following message was received when the syncdb was executed. Did I miss anything?

(myvenv)07:18 ~/my-first-blog (master)$ python manage.py syncdb
/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/core/management/commands/syncdb
.py:24: RemovedInDjango19Warning: The syncdb command will be removed in Django 1.9
  warnings.warn("The syncdb command will be removed in Django 1.9", RemovedInDjango19Warning)
Operations to perform:
  Synchronize unmigrated apps: staticfiles, messages
  Apply all migrations: admin, blog, contenttypes, auth, sessions
Synchronizing apps without migrations:
  Creating tables...
    Running deferred SQL...
  Installing custom SQL...
Running migrations:
  Rendering model states... DONE
  Applying blog.0017_post_day... OK

were you expecting to have anything in particular?

if you had data setup previously in another database, you would have to transfer it over

Thank you conrad, I forgot that my database requires my scheduler to populate it. My website now displays correctly after waiting a day:-)