Wie migrieren Sie Django von lokalem SQLite3 zu postgresql Docker -Container?Python

Python-Programme
Anonymous
 Wie migrieren Sie Django von lokalem SQLite3 zu postgresql Docker -Container?

Post by Anonymous »

Ich versuche, Django mit einigen Demo -Projekten zu lernen und möchte von SQLite3 zu einem lokalen Postgresql -Container für Dev -Arbeiten migrieren. Wenn ich versuche, uv auszuführen python verwalten.py migrate , erhalte ich die folgende Ausnahme:

Code: Select all

django.db.utils.OperationalError: connection failed: connection to server at "127.0.0.1", port 5432 failed: FATAL:  password authentication failed for user "myuser"
Während des Containers ist die Datenbank über PSQL zugegriffen, und mein pg_hba.conf sieht so aus, als ob es eine Authentifizierung zulassen sollte:

Code: Select all

# TYPE  DATABASE        USER            ADDRESS                 METHOD

# "local" is for Unix domain socket connections only
local   all             all                                     trust
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust
# IPv6 local connections:
host    all             all             ::1/128                 trust
# Allow replication connections from localhost, by a user with the
# replication privilege.
local   replication     all                                     trust
host    replication     all             127.0.0.1/32            trust
host    replication     all             ::1/128                 trust

host all all all scram-sha-256
< /code>
Ich erstelle meinen PostgreSQL -Container mit: < /p>
docker run --name=db_container -d -e POSTGRES_DB=mydatabase -e POSTGRES_USER=myuser -e POSTGRES_PASSWORD=mypassword -p 5432:5432 postgres:16.2
< /code>
my .env -Datei enthält: < /p>
POSTGRES_DB=mydatabase
POSTGRES_USER=myuser
POSTGRES_PASSWORD=mypassword
HOST=localhost
PORT=5432
My Settings.py Datei enthält:

Code: Select all

DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': config('POSTGRES_DB'),
'USER': config('POSTGRES_USER'),
'PASSWORD': config('POSTGRES_PASSWORD'),
'HOST': config('HOST'),
'PORT': config('PORT'),
}
}
< /code>
Für zusätzliche Referenz verwende ich Python 3.12 und die folgenden Abhängigkeiten: < /p>
"asgiref>=3.8.1",
"django>=5.1.6",
"django-taggit>=6.1.0",
"markdown>=3.7",
"psycopg>=3.2.5",
"python-decouple>=3.8",
"sqlparse>=0.5.3"
Wie verwende ich einen Postgres -Container als lokale Entwicklerdatenbank in meiner Django -App?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post