tan_000
tan_000

Reputation: 31

Accessing MySQL database with Django

Apologies in advance if this type of question already exists with a solution. I have been trying to get this solved for about 2 weeks now. So I had a Django project, which initially used the default Django database : SQLite3. I was able to access that database using /admin with the localhost, with 'admin' as password and username. I shifted the database to MySQL and everything was transferred properly, but I am not sure how to access the data using the /admin now. What should I enter in the username and password section? I have tried every possible combination with 'admin', database name, username, hostname and password which is provided in the settings.py when you change database.

For reference, this is what the database section of my settings.py looks like

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

Upvotes: 0

Views: 2099

Answers (1)

Joris Jansen
Joris Jansen

Reputation: 56

Chances are that your admin user got lost along the way with this transition from SQLite to MySQL, no worries, I'll provide some instructions down below to create a new one.

There is one thing I would like to mention in order to give you some more context regarding the database configuration in your settings.py file. The USER and PASSWORD credentials that you set over there, are used for connecting to the database itself. This doesn't have anything to do with the admin section of a Django application.

Now in order to create a new admin user, you can follow the steps in the terminal by entering the following command:

python manage.py createsuperuser

Make sure that you enter this command in the root of your project and with your virtualenvironment activated if you have one.

Upvotes: 1

Related Questions