0

My admin does not work. I already tried it for a couple of hours.

The migration works:

C:\Users\sebas\AI_MachineLearning\Django_Projekt\pythonprojects\cookbook>python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, recipes, sessions, sites
Running migrations:
  No migrations to apply.

C:\Users\sebas\AI_MachineLearning\Django_Projekt\pythonprojects\cookbook>

The Superuser is created.

Runserver works:
C:\Users\sebas\AI_MachineLearning\Django_Projekt\pythonprojects\cookbook>python manage.py runserver
Watching for file changes with StatReloader
Performing system checks...

System check identified no issues (0 silenced).
September 18, 2019 - 22:06:57
Django version 2.2.5, using settings 'cookbook.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CTRL-BREAK.

If I try the urls ../admin:

http://dpaste.com/069QF7H


DoesNotExist at /admin/login/

Site matching query does not exist.

Request Method:     GET
Request URL:    http://127.0.0.1:8000/admin/login/?next=/admin/
Django Version:     2.2.5
Exception Type:     DoesNotExist
Exception Value:    

Site matching query does not exist.

Exception Location:     C:\Users\sebas\.conda\envs\pythonDjango\lib\site-packages\django\db\models\query.py in get, line 408
Python Executable:  C:\Users\sebas\.conda\envs\pythonDjango\python.exe
Python Version:     3.6.7
Python Path:    

['C:\\Users\\sebas\\AI_MachineLearning\\Django_Projekt\\pythonprojects\\cookbook',
 'C:\\Users\\sebas\\.conda\\envs\\pythonDjango\\python36.zip',
 'C:\\Users\\sebas\\.conda\\envs\\pythonDjango\\DLLs',
 'C:\\Users\\sebas\\.conda\\envs\\pythonDjango\\lib',
 'C:\\Users\\sebas\\.conda\\envs\\pythonDjango',
 'C:\\Users\\sebas\\.conda\\envs\\pythonDjango\\lib\\site-packages']

Server time:    Mi, 18 Sep 2019 21:55:32 +0200
--------------------------------------------------------------------------
Kevin
  • 16,549
  • 8
  • 60
  • 74
  • Did you add a `path` to your admin site in cookbook\cookbook\urls.py? – Jordan Mora Sep 18 '19 at 20:14
  • INSTALLED_APPS = ( 'django_admin_shell', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', # Uncomment the next line to enable the admin: 'django.contrib.admin', 'recipes' ) – Sebastian Sep 18 '19 at 20:16
  • from django.contrib import admin from django.urls import path urlpatterns = ( #path('admin/', admin.site.urls), #path('admin/', admin.site.urls ), #urlpatterns = [ #path('admin/shell/', django_admin_shell.urls), path('admin/', admin.site.urls), ) – Sebastian Sep 18 '19 at 20:17
  • Hello Jordan, thanks for your answer. Yes I did. – Sebastian Sep 18 '19 at 20:18
  • Looks like your paths are commented. Please add it to your question so we can take a better look at it. – Jordan Mora Sep 18 '19 at 20:19
  • I have tried several variants and therefore commented out a few! urlpatterns = (path('admin/', admin.site.urls),) – Sebastian Sep 18 '19 at 20:21
  • Try removing 'django.contrib.sites' if you're not going to use more than 1 site. Take a look at [this](https://stackoverflow.com/a/9737344/8895630) post. – Jordan Mora Sep 18 '19 at 20:29
  • Thanks a lot. I removed 'django.contrib.sites' and try the commands in the python manage.py shell. It doen't work in my case – Sebastian Sep 18 '19 at 20:41
  • IntegrityError: UNIQUE constraint failed: django_site.id – Sebastian Sep 18 '19 at 20:41
  • '--> 383 return Database.Cursor.execute(self, query, params) 384 385 def executemany(self, query, param_list):' – Sebastian Sep 18 '19 at 20:42
  • After removing `django.contrib.sites` you don't need to run the other command, that's the alternative in case you **do** need to user more than 1 site. You can't do both solutions. Just try to run your server, without creating a `Site` in the `shell` – Jordan Mora Sep 18 '19 at 20:54

1 Answers1

0

Add SITE_ID = 1 in settings.py file.

Arghya Sadhu
  • 41,002
  • 9
  • 78
  • 107
taty
  • 11
  • 1