Ich habe vor kurzem (gestern) beschlossen, Django zu versuchen. Also folgte ich this guideDjango, psycopg2 und Datenbank nicht gefunden
alles scheint gut zu funktionieren, bis ich diesen Befehl versucht:
python manage.py syncdb
Ja ich weiß, syncdb ist depeciated so verwendet i wandern. und dann ist hier, was ich bekommen:
(project)[email protected]:/opt/project/newproject$ python manage.py migrate
Traceback (most recent call last):
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/project/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/project/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
psycopg2.OperationalError: FATAL: database "/opt/project/newproject/demo_db" does not exist
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/opt/project/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
utility.execute()
File "/opt/project/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/opt/project/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
self.execute(*args, **cmd_options)
File "/opt/project/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
output = self.handle(*args, **options)
File "/opt/project/lib/python3.5/site-packages/django/core/management/commands/migrate.py", line 89, in handle
executor = MigrationExecutor(connection, self.migration_progress_callback)
File "/opt/project/lib/python3.5/site-packages/django/db/migrations/executor.py", line 20, in __init__
self.loader = MigrationLoader(self.connection)
File "/opt/project/lib/python3.5/site-packages/django/db/migrations/loader.py", line 49, in __init__
self.build_graph()
File "/opt/project/lib/python3.5/site-packages/django/db/migrations/loader.py", line 176, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "/opt/project/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/opt/project/lib/python3.5/site-packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in self.connection.introspection.table_names(self.connection.cursor()):
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 231, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 204, in _cursor
self.ensure_connection()
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/opt/project/lib/python3.5/site-packages/django/db/utils.py", line 95, in __exit__
six.reraise(dj_exc_type, dj_exc_value, traceback)
File "/opt/project/lib/python3.5/site-packages/django/utils/six.py", line 685, in reraise
raise value.with_traceback(tb)
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 199, in ensure_connection
self.connect()
File "/opt/project/lib/python3.5/site-packages/django/db/backends/base/base.py", line 171, in connect
self.connection = self.get_new_connection(conn_params)
File "/opt/project/lib/python3.5/site-packages/django/db/backends/postgresql/base.py", line 175, in get_new_connection
connection = Database.connect(**conn_params)
File "/opt/project/lib/python3.5/site-packages/psycopg2/__init__.py", line 164, in connect
conn = _connect(dsn, connection_factory=connection_factory, async=async)
django.db.utils.OperationalError: FATAL: database "/opt/project/newproject/demo_db" does not exist
hier ist, was ich verstehen: (oh, wirklich) psycopg2 tut meiner Datenbank zu finden. Ich kann Ihnen versichern, dass es vorhanden ist:
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-----------+----------+-------------+-------------+-------------------------
demo_db | demo_user | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =Tc/demo_user +
| | | | | demo_user=CTc/demo_user
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(4 rows)
Hier mein settings.py ist:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': os.path.join(BASE_DIR, 'demo_db'),
'USER': 'demo_user',
'PASSWORD': 'XXXXXXXXXX',
'HOST': 'localhost',
'PORT':'',
}
}
(Ich habe gerade mit XXX Passwort ersetzt ...) (es sieht nicht so sicher , aber das ist ein anderes Problem)
ich im Internet einige Lösungen gesucht haben, und ich habe dies gefunden: Postgresql & psycopg2: database does not exist
und diese:
Creating a postgresql DB using psycopg2
Aber es hat mir nicht so viel helfen. Könntest du mir bitte helfen, zu verstehen, was hier vorgeht? Vielen Dank)))
Dank auch, ich rly stumm rigth fühle mich jetzt = s – Rainette
@Rainette keine Sorgen. Aus diesem Grund ist es immer eine gute Idee, Code zu überprüfen und andere davon zu überzeugen, dass es sich nicht um sensible Daten handelt. Viel Glück! :) – jape