Я застрял в странной ситуации, когда мне приходится использовать базу данных oracle вместе с Django. Прежде чем начать, я хотел бы упомянуть, что я запускаю базу данных из контейнера docker.
Проблема, с которой я столкнулся, заключается в том, что, хотя база данных запущена и работает, я инициализировал соединение с DataGrip к нему, и он работает просто отлично, когда дело доходит до Django все взрывается.
Вот как я настроил базу данных внутри Django
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.oracle',
'NAME': 'localhost:1521/ORCLCDB.LOCALDOMAIN',
'USER': 'terkea',
'PASSWORD': 'test',
}
}
Но когда я run
python manage.py makemigrations
python manage.py migrate
выдает эту ошибку
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\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\Terkea\AppData\Local\Programs\Python\Python36\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\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\executor.py", line 250, in apply_migration
self.recorder.record_applied(migration.app_label, migration.name)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\recorder.py", line 71, in record_applied
self.migration_qs.create(app=app, name=name)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\query.py", line 417, in create
obj.save(force_insert=True, using=self.db)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 729, in save
force_update=force_update, update_fields=update_fields)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 759, in save_base
updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 842, in _save_table
result = self._do_insert(cls._base_manager, using, fields, update_pk, raw)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 880, in _do_insert
using=using, raw=raw)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\query.py", line 1125, in _insert
return query.get_compiler(using=using).execute_sql(return_id)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\sql\compiler.py", line 1292, in execute_sql
return self.connection.ops.fetch_returned_insert_id(cursor)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\oracle\operations.py", line 228, in fetch_returned_insert_id
return int(cursor._insert_id_var.getvalue())
TypeError: int() argument must be a string, a bytes-like object or a number, not 'list'
И да, я видел, что у гораздо большего количества людей были подобные проблемы с моими. Они предложили попробовать --fake-initial
, но результаты те же. Еще одна вещь, которую я заметил, заключается в том, что после первого запуска упомянутых выше команд в базе данных появятся таблицы DJANGO_CONTENT_TYPE and DJANGO_MIGRATIONS
. Затем, если вы снова запустите команду переноса, появится еще одна ошибка:
$ python manage.py migrate
Operations to perform:
Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
Applying contenttypes.0001_initial...Traceback (most recent call last):
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\oracle\base.py", line 500, in execute
return self.cursor.execute(query, self._param_generator(params))
cx_Oracle.DatabaseError: ORA-00955: name is already used by an existing object
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 371, in execute_from_command_line
utility.execute()
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 365, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 288, in run_from_argv
self.execute(*args, **cmd_options)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\base.py", line 335, in execute
output = self.handle(*args, **options)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\commands\migrate.py", line 200, in handle
fake_initial=fake_initial,
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\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\Terkea\AppData\Local\Programs\Python\Python36\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\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\executor.py", line 244, in apply_migration
state = migration.apply(state, schema_editor)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\migration.py", line 122, in apply
operation.database_forwards(self.app_label, schema_editor, old_state, project_state)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\migrations\operations\models.py", line 92, in database_forwards
schema_editor.create_model(model)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\schema.py", line 314, in create_model
self.execute(sql, params or None)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\base\schema.py", line 133, in execute
cursor.execute(sql, params)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 100, in execute
return super().execute(sql, params)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\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\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 77, in _execute_with_wrappers
return executor(sql, params, many, context)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 85, in _execute
return self.cursor.execute(sql, params)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\utils.py", line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\utils.py", line 83, in _execute
return self.cursor.execute(sql)
File "C:\Users\Terkea\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\backends\oracle\base.py", line 500, in execute
return self.cursor.execute(query, self._param_generator(params))
django.db.utils.DatabaseError: ORA-00955: name is already used by an existing object
Кто-нибудь нашел исправление? Потому что я искал повсюду целый день и не смог найти надежного исправления.