2

I just added a field to my model and added the values of the field to my fixtures. However, I am getting this error:

django.db.utils.ProgrammingError: Problem installing fixture 'app/fixtures/tool.json': Could not load "": column "new_field" of relation "app_model" does not exist

which is the same error I got before even putting values in the fixture. What is it that I'm forgetting?

Here's the Traceback:

Traceback (most recent call last):
  File "./manage.py", line 12, in <module>
    execute_from_command_line(sys.argv)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 367, in execute_from_command_line
    utility.execute()
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 359, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/base.py", line 294, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/base.py", line 345, in execute
    output = self.handle(*args, **options)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 64, in handle
    self.loaddata(fixture_labels)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 104, in loaddata
    self.load_label(fixture_label)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/management/commands/loaddata.py", line 167, in load_label
    obj.save(using=self.using)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/core/serializers/base.py", line 201, in save
    models.Model.save_base(self.object, using=using, raw=True, **kwargs)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/models/base.py", line 824, in save_base
    updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/models/base.py", line 889, in _save_table
    forced_update)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/models/base.py", line 939, in _do_update
    return filtered._update(values) > 0
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/models/query.py", line 654, in _update
    return query.get_compiler(self.db).execute_sql(CURSOR)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 1148, in execute_sql
    cursor = super(SQLUpdateCompiler, self).execute_sql(result_type)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 835, in execute_sql
    cursor.execute(sql, params)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/webapps/my_app/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: Problem installing fixture '/webapps/my_app/tools/fixtures/tools.json': Could not load myapp.model(pk=3): column "new_field" of relation "myapp_model" does not exist
LINE 1: ..._LOCK,android.permission.RECEIVE_BOOT_COMPLETED', "new_field"...
10
  • In the dB the column does not exists for which a value is there in the fixture. You should migrate or double check that there are same attributes in fixture and dB table Commented Jul 26, 2017 at 19:28
  • Since I get this error, it won't let me migrate. Should I simply add this column to the db? @ArpitSolanki Commented Jul 26, 2017 at 19:32
  • 1
    Yeah that could be an option Commented Jul 26, 2017 at 19:33
  • you have any forms for this model ? or if you can show the full traceback it will be beneficial. Commented Jul 26, 2017 at 19:33
  • @Aniket I added the Traceback Commented Jul 26, 2017 at 19:44

1 Answer 1

2

So the way I solved this issue does not make so much sense. I did it by manually adding the column to the table. Then I ran migrate. Since I had the column the second time I was migrating, the error changed to column already exists. So then I deleted the column and it created the column automatically. I am not sure why it did not work in the first place, but if you have this problem, tweak around with the database.

Sign up to request clarification or add additional context in comments.

1 Comment

I had the same problem, I ran python manage.py makemigrations and migrate but got this error. Turns out my app migrations didn't apply as they had been manually deleted before, so I had to recreate an empty database and run python manage.py makemigrations myapp for each app to get it working.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.