Answer the question
In order to leave comments, you need to log in
Have I created a database with such table names correctly and do I always need to make models for the database for migration?
I am creating an application using a database and I want to do it well, and not on a "bluff". This is my first experience and faced such a story. Help to understand, please.
1. Table names.
I have a test db. To create it, I made a separate class and functions, in the functions I registered all queries with SQLite, such as CREATE TABLEs, and so on. The creation of a database takes place in 2 stages: first, tables are created that should always be in this database. and then, as content (more precisely, "very large entities in the project") is added to the database, several more tables are created. These new tables have specific names (this idea came to me in order to avoid filtering by one field, since it is assumed that there can be a lot of data).
Example:
The table, which should always be there, is called "page", it has such fields, for example, id, s_name.
And as large entities are added (from 1 to 5 are assumed), data appears in the page table, for example:
"1, q_test"
"2, w_test"
and two tables q_test and w_test, respectively.
In this way, I tried to separate two entities so as not to add " WHERE s_name = 'q_test' " to the query, for example.
And the question is, is it normal to make tables in this way or is it a very bad idea and is it better to add a field and filter by it, rather than take it ready (because all data is divided into tables)?
2. Models and Migrations
I know it's against the rules to ask multiple questions, but this question stems from the first one.
I created all that DB manually each time. And when adding a new entity, new tables were added to the database.
At first, everything suited me, but then I thought that I needed a web part that didn’t exist before, and then I ran into database migrations.
The problem is that when creating tables on my own (working directly with the sqlite3 module in python), I did not describe the database models anywhere, as happened in the article at the link above. Moreover, these models actively began to participate in migrations.
Do I need to remake the entire database schema for models, or can I bypass models and manually \ directly add data to the database? (sqlite in my case). And what about migrations in order to synchronize copies of the database on different machines?
Help me figure this out :)
If you write a plan of action to fix the horrors from the database, for sure they are here, I will be grateful!
Answer the question
In order to leave comments, you need to log in
Stabilize db. This is the main advice. Migrations are best applied later. There are a lot of utilities for synchronizing instances, including those with different schemes. In a normal case, the process of applying migrations looks like this: you execute the migration scripts sequentially in order. After you update the application count.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question