简体   繁体   中英

Unable to create table in the database using Django oracle12c

I am working on a college project for which I am supposed to use oracle database as the backend and I have chosen to work with django as the programming language. I have successfully connected django with oracle 12c and also have cx_Oracle installed. But when i try to run the command

py manage.py migrate

the following errors show up.

Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.

PS C:\\Users\\Hp\\Desktop\\onlinepharma> py manage.py migrate
Operations to perform: Apply all migrations: admin, auth, contenttypes, sessions, testing Running migrations: Applying contenttypes.0001_initial...Traceback (most recent call last): File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-
packages\\django\\db\\backends\\utils.py", line 83, in _execute return self.cursor.execute(sql) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\oracle\\base.py", line 513, 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 execute_from_command_line(sys.argv) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\core\\management__init__.py", line 381, in execute_from_command_line utility.execute() File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\core\\management__init__.py", line 375, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\core\\management\\base.py", line 316, in run_from_argv self.execute(*args, **cmd_options) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\core\\management\\base.py", line 353, in execute output = self.handle(*args, **options) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\core\\management\\base.py", line 83, in wrapped res = handle_func(*args, **kwargs) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\P ython\\Python37\\lib\\site-packages\\django\\core\\management\\commands\\migrate.py", line 203, in handle fake_initial=fake_initial, File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\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\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\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\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\migrations\\executor.py", line 244, in apply_migration state = migration.apply(state, schema_editor) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\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\\Hp \\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\migrations\\operations\\models.py", line 91, in database_forwards schema_editor.create_model(model) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\base\\schema.py", line 312, in create_model self.execute(sql, params or None) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\base\\schema.py", line 133, in execute cursor.execute(sql, params) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\utils.py", line 100, in execute return super().execute(sql, params) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\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\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\utils.py", line 77, in _execute_with_w rappers return executor(sql, params, many, context) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\utils.py", line 85, in _execute return self.cursor.execute(sql, params) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\utils.py", line 89, in exit raise dj_exc_value.with_traceback(traceback) from exc_value File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\utils.py", line 83, in _execute return self.cursor.execute(sql) File "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\oracle\\base.py", line 513, 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

Here's my model.py file

from django.db import models

# Create your models here.
class yoman(models.Model):
text=models.CharField(max_length=200)

But I have checked using sql command line and no such db table or view exists.

ps: The makemigrations command works properly and the migratiosn file has also been created.

You can print out the sql query if you edit the following file: "C:\\Users\\Hp\\AppData\\Local\\Programs\\Python\\Python37\\lib\\site-packages\\django\\db\\backends\\oracle\\base.py On line 513, before the execute function is called add:

print(f'query')

Rerun the migration and you can see the sql that is failing to run. Either remove or rename the table/object in the db.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM