Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Commands for reverse migration of databases

Shulou Source: shulou.com Published: 2022-06-02 04:35:37 10月03日 Update

This article mainly introduces "the command of database reverse migration". In the daily operation, I believe that many people have doubts about the command of database reverse migration. The editor consulted all kinds of data and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "database reverse migration command"! Next, please follow the editor to study!

In the actual project development, generally do not create a model, and then migrate to the database, because the same database, may correspond to multiple projects, so we need to know how to reverse migration.

Django

Django's orm model already has built-in reverse migration commands.

Python manage.py inspectdb > models.py # > is followed by the path and name of the generated file

Flask

Flask does not configure the relevant reverse migration module.

I have tried several migration packages with specific functions on the Internet, and in the end, I personally feel that sqlacodegen is relatively easy to use. You can install it through the following command.

Pip install sqlacodegen

Execute on the command line

Sqlacodegen mysql:// username: password @ ip: Port number / database > models.py

Similar to django in general, but with more database connections

With this package, pay extra attention to the fact that he will report an error (an error that mysqldb can't find).

Find the appropriate toolkit in the error message, and then paste the following code into it

Import pymysqlpymysql.install_as_MySQLdb ()

Flask is generated in reverse because of the referenced external toolkit, so there are many pits, so you need to pay extra attention to it.

At this point, the study of "database reverse migration command" is over. I hope to be able to solve everyone's doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Data databases commands learning multiple tools toolkits more models errors projects ease of use help generation utility and then personal code information functions Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MariaDB OPPO Reno macOS Linux