anexia / drf-multitokenauth

An extension to Django-Rest-Frameworks Token Authentication, enabling a user to have multiple authorization tokens
BSD 3-Clause "New" or "Revised" License
14 stars 5 forks source link

Error while applying migration #6

Closed SanketSKasarTP closed 4 years ago

SanketSKasarTP commented 4 years ago
Running migrations:
  Applying authtoken.0001_initial... OK
  Applying authtoken.0002_auto_20160226_1747... OK
  Applying django_rest_multitokenauth.0001_initial... OK
  Applying django_rest_multitokenauth.0002_rename_ip_address_20160426... OK
  Applying django_rest_multitokenauth.0003_pk_migration...Traceback (most recent call last):
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/MySQLdb/cursors.py", line 312, in _query
    db.query(q)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/MySQLdb/connections.py", line 224, in query
    _mysql.connection.query(self, query)
MySQLdb._exceptions.OperationalError: (1075, 'Incorrect table definition; there can be only one auto column and it must be defined as a key')

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 "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
    output = self.handle(*args, **options)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/core/management/base.py", line 83, in wrapped
    res = handle_func(*args, **kwargs)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/core/management/commands/migrate.py", line 234, in handle
    fake_initial=fake_initial,
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/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 "/home/sanket/Code/tpayserver/newenv/lib/python3.7/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 "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/migrations/executor.py", line 245, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/migrations/migration.py", line 124, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/migrations/operations/fields.py", line 249, in database_forwards
    schema_editor.alter_field(from_model, from_field, to_field)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 535, in alter_field
    old_db_params, new_db_params, strict)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 685, in _alter_field
    params,
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/base/schema.py", line 137, in execute
    cursor.execute(sql, params)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 67, in execute
    return self._execute_with_wrappers(sql, params, many=False, executor=self._execute)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 76, in _execute_with_wrappers
    return executor(sql, params, many, context)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/utils.py", line 89, in __exit__
    raise dj_exc_value.with_traceback(traceback) from exc_value
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 71, in execute
    return self.cursor.execute(query, args)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/MySQLdb/cursors.py", line 206, in execute
    res = self._query(query)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/MySQLdb/cursors.py", line 312, in _query
    db.query(q)
  File "/home/sanket/Code/tpayserver/newenv/lib/python3.7/site-packages/MySQLdb/connections.py", line 224, in query
    _mysql.connection.query(self, query)
django.db.utils.OperationalError: (1075, 'Incorrect table definition; there can be only one auto column and it must be defined as a key')

I have encountered this multiple times while applying migrations with django 2.2. Seems to be an issue with changing the primary key of a table. Can create a pull request with the fixes that I use, but I am not sure if its my system's issue or the model's issue.

nezhar commented 4 years ago

Similar issue on Django 2.2 and Postgres 10.10 caused by migration 0003:

  Applying django_rest_multitokenauth.0003_pk_migration...Traceback (most recent call last):
  File "/home/snypy/apps/venv/lib/python3.6/site-packages/django/db/backends/utils.py", line 84, in _execute
    return self.cursor.execute(sql, params)
psycopg2.errors.InvalidTableDefinition: multiple primary keys for table "django_rest_multitokenauth_multitoken" are not allowed
ghost commented 4 years ago

Please try to use 1.3.2 as this contains the fix for the migrations.