Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Commands for reverse migration of databases

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report