N
N
nurzhannogerbek2018-01-04 09:24:26
Oracle
nurzhannogerbek, 2018-01-04 09:24:26

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 scaleempty.
The command inspectdbreturns 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
)

This code usually creates the NUMBER data type, but with 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?
2. The table has a title column whose data type is CLOB. I am planning to use the following code:
title = models.TextField(
    verbose_name='Заголовок',
    blank=True,
    null=True
)

Typically, this code creates an NCLOB type in the database. Although inspectdb for the title column returns a TextField too. Question : Is it possible to explicitly specify a type in Django? Will there be any problems during integration?
The whole integration mechanism is not entirely transparent to me. Do I need to do a migration after setting up the data model? Just when trying to make a migration, an error occurs:
django.db.utils.DatabaseError: ORA-00955: name is already used by an existing object

Perhaps the error is due to the fact that in 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

1 answer(s)
A
Artem Sovetnikov, 2018-01-05
@nurzhannogerbek

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 question

Ask a Question

731 491 924 answers to any question