1

I am having trouble moving my Django 1.11 app to production.

There's another question that looks like a similar issue, but I am unable to make the answers suggested in the comments work as desired: Django import errors for app csvimport

if I comment out the code in settings.py to remove the django-csvimport library stuff like so:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
   # 'csvimport.app.CSVImportConf',
    'custom_app_name',

]

then my migrations work fine, and the app runs(sans csvimport app). Then if I comment the csvimport APP line back in and run the migrations, they fail with the following:

Operations to perform:
  Apply all migrations: admin, auth, contenttypes, csvimport, sessions, custom_app_name
Running migrations:
  Applying csvimport.0002_test_models...Traceback (most recent call last):
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
psycopg2.ProgrammingError: syntax error at or near "csvtests_country"
LINE 1: ...CONSTRAINT "csvtests_item_country_id_5f8b06b9_fk_"csvtests_c...
                                                             ^


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

Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    execute_from_command_line(sys.argv)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
    utility.execute()
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/__init__.py", line 356, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/base.py", line 283, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/base.py", line 330, in execute
    output = self.handle(*args, **options)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/core/management/commands/migrate.py", line 204, in handle
    fake_initial=fake_initial,
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/migrations/executor.py", line 115, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/migrations/executor.py", line 145, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/migrations/executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 93, in __exit__
    self.execute(sql)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/base/schema.py", line 120, in execute
    cursor.execute(sql, params)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 80, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/utils.py", line 94, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/utils/six.py", line 685, in reraise
    raise value.with_traceback(tb)
  File "/home/www-root/envs/django_env_1/lib/python3.4/site-packages/django/db/backends/utils.py", line 65, in execute
    return self.cursor.execute(sql, params)
django.db.utils.ProgrammingError: syntax error at or near "csvtests_country"
LINE 1: ...CONSTRAINT "csvtests_item_country_id_5f8b06b9_fk_"csvtests_c...

Any advice would be very helpful.
Thanks!

totaltotals
  • 703
  • 2
  • 7
  • 16

1 Answers1

2

So I was able to fix this issue based on the stack trace error which read:

django.db.utils.ProgrammingError: syntax error at or near 
"csvtests_country"
LINE 1: ...CONSTRAINT "csvtests_item_country_id_5f8b06b9_fk_"csvtests_c...

The issue was that there was a piece of generated code which added double quotes inside of single quotes, like so:

 options={
                'managed': True,
                'db_table': '"csvtests_country"',
            },

To find the migration I went to my virtual environment's python install:

django_env/lib/python3.4/site-packages/csvimport/migrations/

and removed the double quotes based on the fact that none of the other 'db_table' : 'sometable_name' calls used double-quotes. I guess this is a bug that I'll be reporting to the csvimport github page. I will post any updates to this question if I find more information.

Hopefully this helps someone in a similar situation.

Thanks!


UPDATE:

I did not see this in the issue list from the csvimport github page before. It appears to be a known bug: https://github.com/edcrewe/django-csvimport/issues/77

totaltotals
  • 703
  • 2
  • 7
  • 16