How can I see my MySQL database in Django admin site?

Viewed 1418

I am developing a Django application and I have created a MySQL database (I am using Laragon to manage it) and connected it with the App. I am using the database for another Python script that inserts data in the database too. What I want it to see all the database data in my Django admin site, but for some reason, I can't manage to do it? Do I have to add the tables to the Django models? or what should I do?

My settings.py:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'nlpwords',
    'USER': 'root',
    'PASSWORD': '',
    'HOST': 'localhost',
    'PORT': 3306,
}

}

enter image description here

I am using that database that has some data in some of the tables, but when I enter localhost/admin in my Django app I can't manage to see all those tables. Help is much appreciated.

1 Answers

To see your Django apps in your admin portal, you need to register them in admin.py.

Example:

# admin.py
from django.contrib import admin
from .models import *

admin.site.register(ModelName)

Note: if you just made a new app and recently created models, make sure to run makemigrations and migrate so it gets registered to the db first.

Related