silverapp / silver

Automated billing and payments for Django with a REST API
https://www.presslabs.com/code/silver/
Other
301 stars 80 forks source link

Initial Migration Failing Django 2.1.3 / Postgres 11.2 #645

Closed ajaff closed 5 years ago

ajaff commented 5 years ago

Hi,

I am new to using Silver - I just downloaded the silver app and tried to run the migration however I am receiving the below error.

Django 2.1.3 PostgreSQL 11.2


Operations to perform:
  Apply all migrations: silver
Running migrations:
  Applying silver.0001_initial... OK
  Applying silver.0002_auto_20150416_1009... OK
  Applying silver.0003_auto_20150417_0634... OK
  Applying silver.0004_auto_20150429_1731... OK
  Applying silver.0005_auto_20150429_1732... OK
  Applying silver.0006_auto_20150430_1457... OK
  Applying silver.0007_auto_20150430_1549... OK
  Applying silver.0008_auto_20150430_1804... OK
  Applying silver.0009_auto_20150717_1428... OK
  Applying silver.0031_auto_20170125_1343...Traceback (most recent call last):
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.StringDataRightTruncation: value too long for type character varying(4)

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

Traceback (most recent call last):
  File "manage.py", line 16, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\core\management\__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\core\management\base.py", line 316, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\core\management\base.py", line 353, in execute
    output = self.handle(*args, **options)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\core\management\base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\core\management\commands\migrate.py", line 203, in handle
    fake_initial=fake_initial,
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\migrations\executor.py", line 117, in migrate
    state = self._migrate_all_forwards(state, plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\migrations\executor.py", line 147, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
    state = migration.apply(state, schema_editor)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\migrations\migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\migrations\operations\fields.py", line 84, in database_forwards
    field,
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\base\schema.py", line 435, in add_field
    self.execute(sql, params)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
    cursor.execute(sql, params)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\utils.py", line 100, in execute
    return super().execute(sql, params)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\utils.py", line 68, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "C:\Users\Ahmed\OneDrive\Documents\RESX\Code\tornado\venv\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
    return self.cursor.execute(sql, params)
django.db.utils.DataError: value too long for type character varying(4)
ajaff commented 5 years ago

I was able to get around it for now by changing max_length=4 to max_length=6 in migration 0031.

bogdanpetrea commented 5 years ago

Hey @ajaff, that's strange. The currency codes that are in use should be no longer than 3 characters. Also max_length was 4 even before that migration, so it's even stranger. Too bad it doesn't say what value is too long.

shurph commented 5 years ago

Hi @ajaff and @bogdanpetrea, it causes by binary strings as default value for CharField.

shurph commented 5 years ago

I uncluded fix for this issue in #646 PR.

Here is concrete commit: https://github.com/silverapp/silver/pull/646/commits/0bbb0542ebd577213914bcbf8b76f185a3bdec1f