Answer the question
In order to leave comments, you need to log in
How to correctly integrate Django with a legacy database?
Hello! Please help me figure it out.
There is a database on Oracle with the table. A table stores lots of data. You need to create a data model based on the previously mentioned table. The problems are as follows:
1. This table has a tab column with type NUMBER
. At the same time precision
, they are scale
empty.
The command inspectdb
returns for some reason tab = models.FloatField()
, although it seems like FloatField will not create the NUMBER data type in the database. So I settled on the following code:
tab = models.IntegerField(
verbose_name='Вкладка',
choices=TAB_CHOICES,
default=0,
blank=True,
null=True
)
precision=11, scale=0
. Question : will there be any problem when migrating to an existing database (table) with the current code, or how to set empty values for precision and scale? title = models.TextField(
verbose_name='Заголовок',
blank=True,
null=True
)
django.db.utils.DatabaseError: ORA-00955: name is already used by an existing object
db_table
, which is in the Meta class, there is a table name.
Answer the question
In order to leave comments, you need to log in
The error says that the table with the specified name cannot be created - it already exists in the database.
In short, you need to do manage.py migrate --fake [appname] (appname is the name of your module), Django will mark the initial migration in the database as completed and will not touch the database itself.
But, because django uses service tables, first do manage.py migrate django.
According to paragraphs 1 and 2 - try it in practice. As I understand it, you are not going to modify the schema through Django? Then just try that Django can read and write to your database. Generate data https://github.com/vandersonmota/model_mommy and read it.
Once again, keep in mind that Django creates a bunch of service tables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question