0

Saludos tengo una app con django-db-multitenant la cual funciona bien el problema surge al tratar de realizar una migración:

TENANT_DATABASE_NAME=rg python manage.py migrate

Con makemigrations funciona bien se genera el archivo .py, el problema surge al colocar el migrate, el error que genera:

[roo@rgmanagement_2 facturacion]$ TENANT_DATABASE_NAME=rg python manage.py migrate
Operations to perform:
  Apply all migrations: correo, empresa, sessions, personal, admin, proveedores, ordenescompra, seguridad, auth, cartera, bodegas, movimientos, contenttypes, custodias, clientes, contabilidad, productos, secuencias, ordenespedido, ventas
Running migrations:
  Rendering model states... DONE
  Applying seguridad.0004_auto_20190709_1300...Traceback (most recent call last):
  File "manage.py", line 8, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/usr/lib64/python2.7/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib64/python2.7/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/usr/lib64/python2.7/site-packages/django/core/management/commands/migrate.py", line 200, in handle
    executor.migrate(targets, plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 92, in migrate
    self._migrate_all_forwards(plan, full_plan, fake=fake, fake_initial=fake_initial)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 121, in _migrate_all_forwards
    state = self.apply_migration(state, migration, fake=fake, fake_initial=fake_initial)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/executor.py", line 198, in apply_migration
    state = migration.apply(state, schema_editor)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/migration.py", line 123, in apply
    operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
  File "/usr/lib64/python2.7/site-packages/django/db/migrations/operations/models.py", line 202, in database_forwards
    new_model._meta.db_table,
  File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 359, in alter_db_table
    "new_table": self.quote_name(new_db_table),
  File "/usr/lib64/python2.7/site-packages/django/db/backends/base/schema.py", line 110, in execute
    cursor.execute(sql, params)
  File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib64/python2.7/site-packages/django/db/utils.py", line 95, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/usr/lib64/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/usr/lib64/python2.7/site-packages/django/db/backends/mysql/base.py", line 112, in execute
    return self.cursor.execute(query, args)
  File "/usr/lib/python2.7/site-packages/pymysql/cursors.py", line 165, in execute
    result = self._query(query)
  File "/usr/lib/python2.7/site-packages/pymysql/cursors.py", line 321, in _query
    conn.query(q)
  File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 860, in query
    self._affected_rows = self._read_query_result(unbuffered=unbuffered)
  File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 1061, in _read_query_result
    result.read()
  File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 1349, in read
    first_packet = self.connection._read_packet()
  File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 1018, in _read_packet
    packet.check_error()
  File "/usr/lib/python2.7/site-packages/pymysql/connections.py", line 384, in check_error
    err.raise_mysql_exception(self._data)
  File "/usr/lib/python2.7/site-packages/pymysql/err.py", line 107, in raise_mysql_exception
    raise errorclass(errno, errval)
django.db.utils.InternalError: (1017, u"Can't find file: './rg/seguridad_configuracioninicial.frm' (errno: 2 - No such file or directory)")

Tengo agregado las configuraciones respectivas tal cual indica en la documentación

Management Commands

uso esta versión de Django Multitenant para usarlo con MySql dado que las otras son para Oracle ó PostgreSql.

Quizá alguna sugerencia gracias de antemano.

1
  • 1
    elimina la carpeta migrations, generalas de nuevo y ejecuta el comando, probablemente hicistes tantos cambios en el modelo que el seguridad.0004_auto_20190709_1300 te da problema de relacion Commented el 9 jul. 2019 a las 19:26

1 respuesta 1

2

Sin duda me ayudo el comentario de JackNavaRow .

Para resolver dicho problema lo que hice fue eliminar el archivo en conflicto de la carpeta migrations de mi app.

Adicional a esto Django por defecto posee una tabla django_migrations en la cual registra las migraciones realizadas, por ende también eliminé dicho registro que causaba conflictos y con esto realicé nuevamente el migrate con éxito.

Espero a alguien mas le sirva..!!

Tu Respuesta

By clicking “Publica tu respuesta”, you agree to our terms of service and acknowledge you have read our privacy policy.

¿No es la respuesta que buscas? Examina otras preguntas con la etiqueta o formula tu propia pregunta.