Edit skip first part, I found out (well, they tell me) that the problem is in the database \edit
I Have a python+django project that I keep on two computers. I mean have two copy of the same project and sometimes I work on one, sometimes on the other. With copy-paste I lose the secret key in a settings.py (they were different but I overwrite). I don't know how generation and storage of secret keys works but to recover I start a new project, took the key and copied the files like this:
1) make a copy of the project
2) deleted the original project but kept the copy
3) started a new project with the same name (so, in the same folder like the original)
4) copied the new secret key
5) copied the files from the copy of the old project in the new project (so settings.py is lost and the new secret key with it, but I have a copy)
6) changed the secret key with the new secret key
But this don't works and it gives the same error like before:
System check identified no issues (0 silenced).
Unhandled exception in thread started by <function check_errors.<locals>.wrapper
at 0x0000000004ADAEA0>
Traceback (most recent call last):
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\po
stgresql\base.py", line 174, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\psycopg2\__init__.py"
, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: FATALE: autenticazione con password fallita per l'ut
ente "gm"
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\utils\autorelo
ad.py", line 225, in wrapper
fn(*args, **kwargs)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\core\managemen
t\commands\runserver.py", line 120, in inner_run
self.check_migrations()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\core\managemen
t\base.py", line 442, in check_migrations
executor = MigrationExecutor(connections[DEFAULT_DB_ALIAS])
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
executor.py", line 18, in __init__
self.loader = MigrationLoader(self.connection)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
loader.py", line 49, in __init__
self.build_graph()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
loader.py", line 209, in build_graph
self.applied_migrations = recorder.applied_migrations()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
recorder.py", line 61, in applied_migrations
if self.has_table():
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\migrations\
recorder.py", line 44, in has_table
return self.Migration._meta.db_table in self.connection.introspection.table_
names(self.connection.cursor())
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 255, in cursor
return self._cursor()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 232, in _cursor
self.ensure_connection()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\utils.py",
line 89, in __exit__
raise dj_exc_value.with_traceback(traceback) from exc_value
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 216, in ensure_connection
self.connect()
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\ba
se\base.py", line 194, in connect
self.connection = self.get_new_connection(conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\django\db\backends\po
stgresql\base.py", line 174, in get_new_connection
connection = Database.connect(**conn_params)
File "C:\Users\Fabio\Envs\possedimenti\lib\site-packages\psycopg2\__init__.py"
, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: FATALE: autenticazione con password fallita p
er l'utente "gm"
translated: authentication with password failed for user 'gm'
I'm not sure when it happened the first time but I have another problem, probabily linked: I can't access the database. Maybe this is the cause of the first problem and not the secret key.
I use PostgreSQL and I access it using the utility standard pgAdmin III. It gives me the initial screen with Servers: PostgreSQL 9.5, I right click on it and select connect, it ask me for password, I gives but it throws an error:
An error has occurred. Error connecting to the server: FATALE: autenticazione con password fallita per l'utente 'postgres'.
translated: authentication with password failed for user 'postgres'
I have created only one database and user so I have the standard postgres and my database 'possedimenti_db' with an user called 'gm'.
What can I do? I don't mind the data present, I can delete all but if it don't make me access I don't know how to delete.
Thank you
My settings.py:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'possedimenti_db',
'USER': 'gm',
'PASSWORD': database_key,
'HOST': host_key,
'PORT': '5432',
}
}
database_key and host_key are imported from external file.
Also database_key is different from the password I use to access the database with pgAdmin. In my other pc it works. I tried to change it in the other password but it throws anyway the same error.
Edit You Can read the solution in the comments of the answer but the problem was that my user hadn't a password definited.