Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pyCharm and django admin

I'm trying to run a Django admin page in PyCharm.

I've created a test project with an empty test app and a simple model.

class User(models.Model):
    name = models.CharField(max_length=15)
    email = models.EmailField()

As I open 127.0.0.1:8000/admin/ I can see the admin page. However, not only I don't know where the password is (I don't recall setting any password so far) but trying to login will crash the server with this error:

OperationalError at /admin/

no such table: auth_user

Exception Location: /Library/Python/2.7/site-packages/django/db/backends/sqlite3/base.py in execute, line 451

Why? And how can I set a password?

like image 802
Saturnix Avatar asked Jan 10 '23 14:01

Saturnix


1 Answers

In a terminal, cd into your project root and type ./manage.py syncdb. This will create the initial tables.

When it gets around to creating the auth_user table, it will ask you to create an admin user, and set a password on it. These are the credentials you need to log in to the admin interface.

Edit: For those using Django 1.7+, the correct command to sync your database initially is now ./manage.py migrate. Keep in mind that this will not prompt you to create an admin user automatically. In order to bring up the prompt, run the command ./manage.py createsuperuser.

like image 154
huu Avatar answered Jan 21 '23 06:01

huu