简体   繁体   English

如何为现成的数据库制作django管理面板?

[英]How to make a django admin panel for a ready database?

how to make a django admin panel for a ready mysql database ? 如何为现成的mysql数据库制作django管理面板?

I have a mysql database with tables and records in it , i want to make an admin panel for it how can i do that ? 我有一个带有表和记录的mysql数据库,我想为其创建一个管理面板,我该怎么做?

i searched and there was no strict answer for it . 我搜寻了,没有严格的答案。 any suggestions will be helpfull , thanks to this great community . 感谢这个伟大的社区,任何建议都会有帮助。

Yes, If your connection with database is done then you can simple run this command in your terminal to generate models for your models.py : 是的,如果完成了与数据库的连接,那么您可以在终端中简单地运行以下命令来为您的models.py生成模型

python manage.py inspectdb > models.py

A new models.py file will be created on project level so you basically copy the code and save it in your App/models.py . 在项目级别将创建一个新的models.py文件,因此您基本上可以复制代码并将其保存在App/models.py Then run your migrations: 然后运行您的迁移:

python manage.py makemigrations app

Then 然后

python manage.py migrate

After this you have to import all tables in your admin.py and register them like this: 之后,您必须在admin.py导入所有表,并像这样注册它们:

from .models import *

admin.site.register(#modelname)

Run this command to download mysqlclient - pip install mysqlclient 运行此命令以下载mysqlclient - pip install mysqlclient

Add This settings in your settings.py 在您的settings.py添加此settings.py

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'myproject',                        #<-- database name
    'USER': 'myprojectuser',                    #<-- database username
    'PASSWORD': 'password',                     #<-- database password
    'HOST': 'localhost',
    'PORT': '5432',                             #<-- Change it port you're using
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM