Django 1.7 makemigrations not working - has no column named

I can't figure out why my makemigrations isn't working with sqlite. When I add the column userphoto and go to make migrations, I receive an error message "table categories_Category has no column named userphoto"

python 3.4, django 1.7, only added userphoto

class Category(models.Model):
    username = models.CharField(max_length=15)
    realname = models.CharField(max_length=20)
    tweets = models.CharField(max_length=1000)
    tweettime = models.DateTimeField(max_length=30)
    tweetidnum = models.CharField(max_length=30)
    userphoto = models.CharField(max_length=100)

and receive the error message below:

File "/Users/xxxxxxxxx/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
       django.db.utils.OperationalError: table categories_category has no column named userphoto

it also seems as though this could be just a sqlite3 issue? Would I be able to avoid this by shifting to my webhosts server?

EDIT: Full traceback per request

(tg)boo!:tg spencertachick$ python manage.py makemigrations
    /Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/fields/__init__.py:1282: RuntimeWarning: DateTimeField Category.tweettime received a naive datetime (2015-03-04 16:01:00) while time zone support is active.
    RuntimeWarning)

Traceback (most recent call last):
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
    sqlite3.OperationalError: table categories_category has no column named userphoto

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
      File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/core/management/__init__.py", line 385, in execute_from_command_line
    utility.execute()
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/core/management/__init__.py", line 354, in execute
    django.setup()
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/__init__.py", line 21, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/apps/registry.py", line 108, in populate
    app_config.import_models(all_models)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/apps/config.py", line 202, in import_models
    self.models_module = import_module(models_module_name)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/importlib/__init__.py", line 109, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
  File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
  File "<frozen importlib._bootstrap>", line 2226, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 1200, in _load_unlocked
  File "<frozen importlib._bootstrap>", line 1129, in _exec
  File "<frozen importlib._bootstrap>", line 1471, in exec_module
  File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
  File "/Users/spencertachick/anaconda/envs/tg/tg/categories/models.py", line 54, in <module>
    tweetidnum=user_timeline[x]['id_str'])
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/query.py", line 372, in create
    obj.save(force_insert=True, using=self.db)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 589, in save
    force_update=force_update, update_fields=update_fields)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 617, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 698, in _save_table
    result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/base.py", line 731, in _do_insert
    using=using, raw=raw)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/manager.py", line 92, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/query.py", line 921, in _insert
    return query.get_compiler(using=using).execute_sql(return_id)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/models/sql/compiler.py", line 920, in execute_sql
    cursor.execute(sql, params)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 81, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/utils/six.py", line 658, in reraise
    raise value.with_traceback(tb)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/Users/spencertachick/anaconda/envs/tg/lib/python3.4/site-packages/django/db/backends/sqlite3/base.py", line 485, in execute
    return Database.Cursor.execute(self, query, params)
django.db.utils.OperationalError: table categories_category has no column named userphoto

Line 54 in categories/models.py:

tweetidnum=user_timeline[x]['id_str'])

That is apparently somehow trying to create aCategoryinstance and save it when the module is imported. This prevents the migration from running at all, as an uncaught exception is raised before the migrations get a chance to run.

You'll have to provide more code if you want the exact cause, but that line is the culprit. I suspect it is part of a multi-linecreatestatement.

Your migrations weren't applied correctly.

Do apython manage.py migrate -l categories. It should list the applied migrations in that app. Have a look at the last one (or the one you thinkuser_photohad to be added) and watch the file.

Once you identify which is the migration that has to add the field, do apython manage.py migrate polls $prevwhere $prev is the previous migration in the list andpython manage.py migrate polls $migrationwhere $migration is the one adding the field.

If this does not work, I would say that the fastest approach without losing data is creating the column yourself withALTER TABLE categories ADD COLUMN "userphoto" varchar(100) NOT NULL;

What Others Are Reading