Introduction
Upon the attempt to create a migration script by running a certain command, it trigger an error message. Actually, it is appear on the title of this article. For the complete error message, it exist as follows :
(env) C:programmingpythondjangomyproject>python manage.py makemigrations C:apppython39libsite-packagesdjangocoremanagementcommandsmakemigrations.py:105: RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': FATAL: password authentication failed for user "django_postgres" warnings.warn( No changes detected (env) C:programmingpythondjangomyproject>
This article has a relation with the previous one. That article is an article with the title of ‘How to Present or Display a File using the HttpResponse Object in Django Application’ in this link. Furthermore, the described application in that article is becoming the reference which is triggering error in this article. The above command is actually a command which is an attempt to solve an error message appear in another article. The article is an article with the title of ‘How to Solve Error Message Programming Error relation does not exist on accessing Django Application’ in this link. So, before going on to the solution the following is the conditions of the application. First of all, the most important thing is the database configuration connection in the ‘settings.py’ file. It exist in the project folder. The following is the configuration lines :
DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'USER': 'django_postgres', 'NAME': 'sysapp', 'PASSWORD': 'password', }
Solution
Actually, the solution is simple. Just try to access the PostgreSQL database server. Check whether the user account is available for connecting to the PostgreSQL database server. The following is an attempt for accessing it with the series of steps for solving the problem :
-
First of all, try to access the PostgreSQL database server using the database configuration connection exist in the ‘settings.py’ file :
C:>psql -Udjango_postgres -d sysapp Password for user dafadf: psql: error: connection to server at "localhost" (::1), port 5432 failed: FATAL: password authentication failed for user "django_postgres" C:>
-
Since the process for connecting to the database ends in a failure, just check the database for the account. Login to the PostgreSQL database server using any available admin account as follows :
C:>psql -Upostgres Password for user postgres: psql (14.0) WARNING: Console code page (437) differs from Windows code page (1252) 8-bit characters might not work correctly. See psql reference page "Notes for Windows users" for details. Type "help" for help. postgres=#
-
Next, after successfully logging in. Just list any available users in the PostgreSQL database server by running the following command :
postgres=# du+ List of roles Role name | Attributes | Member of | Description -----------------+------------------------------------------------------------+-----------+------------- postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {} | postgres=#
-
Following after, apparently there only one user account available. In that case, just create a new user in the PostgreSQL which is used to connect from Django-based project or application. Read the article in this link with the title of ‘How to Create User in PostgreSQL Database Server’. Another one with the same content available in this link with the same title which is also ‘How to Create User in PostgreSQL Database Server’. But there are several main different exist in the syntax. It exist as follows with directly a real example :
postgres=# create user django_postgres with encrypted password 'password'; CREATE ROLE postgres=#
-
Don’t forget to assign the correct privileges to the new created user by executing the following command :
postgres=# grant all on database sysapp to django_postgres; GRANT postgres=#
-
Finally, just try to execute the command for running the migration generation script process Django-based internal service once more. If there are no further error appear, it will run normally.
I write
Python3 Manage.py MakeMigrations.
And get
/library/frameworks/python.framework/versions/3.9/lib/python3.9/site-packages/django/core/management/commands/makemigrations.py:105: RuntimeWarning: Got An Error Checking A Consistent Migration History Performed for Database Connection 'Default': Could Not Connect To Server: No Such File or Directory
IS The Server Running Locally and Accepting
Connections on Unix Domain Socket "/tmp/.s.pgsql.5432"?
Warnings.warn (
/Library/Framework/Python.Framework/Versions/3.9/lib/python3.9/site-packages/django_currentuser/db/models/fields.py: Userwarning: You Passed An Argument to CurrentUserfield That Will Be Ignored. Avoid Args and Following Kwargs: Default, Null, To.
Warnings.warn (self.warning)
No Changes Detected.
I’m new to Django, translate -transferred a mistake, but I don’t understand it, I will be glad to any help
CurrentUserfield
Import Warnings
From Django.conf Import Settings
From Django.db Import Models
From django.utils.translation Import GetText_Lazy AS _
From django_currentuser.middleware Import Get_current_authenticated_user
Class CurrentUSERFIELD (Models.ForeignKey):
Warning= ("You Passed An Argument to CurrentUSERFIELD THAT WILL BE"
"Ignored. Avoid Args and Following Kwargs: Default, Null, To.")
description= _ (
'AS Default Value Sets The Current Logged in User If Available')
Defaults= DICT (NULL= TRUE, DEFAULT= get_current_authenticated_user,
to= settings.auth_user_model)
Def __init __ (Self, * Args, ** kwargs):
self.on_update= kwargs.pop ("On_update", False)
self._warn_for_shadowing_args (* Args, ** kwargs)
if "On_delete" not in kwargs:
kwargs ["on_delete"]= models.cascade
If self.on_update:
kwargs ["editable"]= false
kwargs ["blank"]= true
kwargs.update (Self.Defaults)
Super (CurrentUSERFIELD, SELF) .__ INIT __ (** kwargs)
DEF DECONSTRUCT (SELF):
Name, Path, Args, Kwargs= Super (CurrentUSERFIELD, SELF) .DECONSTRUCT ()
If self.on_update:
kwargs ['on_update']= self.on_update
Del Kwargs ["Editable"]
Del Kwargs ["Blank"]
Return Name, Path, Args, Kwargs
DEF PRE_SAVE (Self, Model_instance, Add):
If self.on_update:
Value= get_current_authenticated_user ()
IF Value Is Not None:
Value= value.pk.
SetAttr (Model_instance, Self.attname, Value)
Return Value.
ELSE:
Return Super (CurrentUSERFIELD, SELF) .PRE_Save (Model_instance, Add)
DEF _WARN_FOR_SHADOWING_ARGS (Self, * Args, ** kwargs):
IF Args:
Warnings.warn (self.warning)
ELSE:
For key in set (kwargs) .intersection (SET (Self.Defaults.keys ())):
If not kwargs [Key]== Self.Defaults [Key]:
Warnings.warn (self.warning)
Break
Thank you all
#32864
closed
Bug
(duplicate)
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Core (Management commands) | Version: | 3.2 |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | yes |
When I first create a project (even if you delete all the migration and database files), and you run python manage.py makemigrations, it gives you the following error:
C:UserssamarAppDataLocalProgramsPythonPython39Libsite-packagesdjangocoremanagementcommandsmakemigrations.py: 105: RuntimeWarning: Got an error checking a consistent migration history performed for database connection default: Unable to open database file. Warnings.Warn(…)
This isn’t its usual behavior as I don’t have a database file and I’m working with SQLite3 and have some models in some of my apps and no migrations, so it should ideally create the database file and the migration files for me to be able to migrate into the database with manage.py migrate. However, on top throwing this warning, it doesn’t create the migration files or the database file. If it helps, my code is on GitHub at http://github.com/samarth466/∴ess.git.
Unable to use python manage.py migrate
When I am trying to add a user for in my django admin site I get this error:
The above exception (NOT NULL constraint failed: auth_user.last_login) was the direct cause of the following exception:
/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py in get_response
I created the Super user with this command: python manage.py supersuser and was able to login with it. However, adding a user is giving me grief on proceeding with the site.
Lluvian
|
29
posts
|
Sept. 1, 2016, 10:21 p.m.
|
permalink
double check you are using the right version of python when you run migrate/when you are running your webapp.
also are you getting an error when running migrate? or when adding a user on django admin
conrad
|
4233
posts
|
PythonAnywhere staff
|
Sept. 2, 2016, 10:27 a.m.
|
permalink
I am guessing the site by default is using python 3 based on the error. Below is what I ran the error it shows.
$ python manage.py migrate
Unknown command: ‘migrate’
Type ‘manage.py help’ for usage.
Lluvian
|
29
posts
|
Sept. 2, 2016, 3:38 p.m.
|
permalink
Our linux system uses python2.7 as the default system python. The webapp you have setup is a python3.5 webapp (you can see this by going to the webapps tab and searching for python version).
To run manage.py migrate, use python3.5
conrad
|
4233
posts
|
PythonAnywhere staff
|
Sept. 2, 2016, 9:54 p.m.
|
permalink
I may have selected to use python 3.5 by accident. I tried using python3 manage.py migrate and it returns the same error as above that its an unrecognized command. I will research why that is happening.
-Thanks
Lluvian
|
29
posts
|
Sept. 2, 2016, 10:21 p.m.
|
permalink
From my research, I was missing south for some reason in my settings.py installed apps. I added it and was able to migrate. Now the site is not running. More research to come but thank you all for helping.
Something went wrong
This website is hosted by PythonAnywhere, an online hosting environment. Something went wrong while trying to load it; please try again later.
If this is your PythonAnywhere-hosted site, and you just reloaded it, then the problem might simply be that it hasn’t loaded up yet. Try refreshing this page and see if this message disappears.
If you keep getting this message, you should check your site’s server and error logs for any messages — you can view them from the Web tab inside PythonAnywhere.
If there’s nothing in the logs, and you’re sure your site is OK, then it might be a problem on our side. Drop us a line at support@pythonanywhere.com, in the forums, or using the «Send feedback» link on the site, quoting the error code below.
Error code: 502-backend
Lluvian
|
29
posts
|
Sept. 2, 2016, 10:34 p.m.
|
permalink
I am close to giving up on the project and may start over. I never had this many issues when building a server and creating the app from within.
There is no South database module ‘south.db.sqlite3’ for your database. Please either choose a supported database, check for SOUTH_DATABASE_ADAPTER[S] settings, or remove South from INSTALLED_APPS.
Lluvian
|
29
posts
|
Sept. 2, 2016, 11:21 p.m.
|
permalink
So I delete the app and started over again.
Steps:
1. Select to create a new app.
2. Gave it a domain name.
3. Selected Django 1.9 with python 3.5
4.
python3 manage.py migrate
Unknown command: ‘migrate’
Type ‘manage.py help’ for usage.
5.
python3 manage.py syncdb
You just installed Django’s auth system, which means you don’t have any superusers defined.
Would you like to create one now? (yes/no): yes
6. User was added
7. Login to the site/admin with the created user and try to add a new user.
8. Exception Value:NOT NULL constraint failed: auth_user.last_login
Lluvian
|
29
posts
|
Sept. 3, 2016, 4:24 a.m.
|
permalink
I think that you’re using a version of Django on PythonAnywhere than the code is written for. Make sure that the version of Django you’re using on PythonAnywhere is the same as the one that you expect.
glenn
|
8703
posts
|
PythonAnywhere staff
|
Sept. 3, 2016, 8:42 a.m.
|
permalink
Hi Glenn. Can that be the case if I used pythonanywhere’s template to build the site? It matches python version with django version?
Django Version: 1.9.3
Python Version: 3.5
Lluvian
|
29
posts
|
Sept. 3, 2016, 10:26 a.m.
|
permalink
I downgraded to python 3.4 and it works. The default template for python 3.5 and django 1.9 does not work.
Lluvian
|
29
posts
|
Sept. 3, 2016, 5:47 p.m.
|
permalink
That’s interesting. We’ll have to investigate what may be going on there.
glenn
|
8703
posts
|
PythonAnywhere staff
|
Sept. 4, 2016, 10:36 a.m.
|
permalink
Having closely read your posts above, I think the problem you were having was because you were using the command python3
in your bash consoles when you were running the manage.py
scripts, instead of using python3.5
.
In newly-created PythonAnywhere accounts, python3
starts Python 3.5 (which is probably why my colleagues didn’t pick up on this). But in order to avoid breaking backward-compatibility, for older accounts it maps to the most recent version of Python 3 at the time the account was created. For your account, this means it points to Python 3.4.
This explains the weird behaviour you saw. Our current system install of Django for Python 3.4 is 1.6, and for Python 2.7 it’s 1.3.7. So the errors you saw Django version mismatch errors, because you’d selected Python 3.5 but were running with one or the older versions.
A couple of follow-on points:
-
When you are using Django management commands, you don’t actually need to specify the Python interpreter. If you’re in the directory that contains
manage.py
, then you can just do things like this:This means that you don’t need to remember anything about the Python version — it just works.
* You mention south, which doesn’t exist in Django 1.9 — database migrations were integrated into Django in Django 1.7.
Just for completeness — I created a Django 1.9 app using Python 3.5 in a fresh account, and here are the steps I followed:
- «Add a new web app»
- «Django»
- «Python 3.5 (Django 1.9.3)»
- Just accepted the defaults on the next page
- Checked that the basic site (without admin) showed a «Welcome to Django» page.
- Went to «/admin» on the basic site and confirmed I had a page there.
- Went to a bash console
-
Ran
cd mysite ./manage.py migrate ./manage.py createsuperuser
-
Logged in to the admin site.
- Clicked on the «Add user» link
- Entered username and password for a user
- Clicked «Save».
That all worked fine. Because those steps bypass the need to name the specific Python version on the Bash command line by running manage.py
directly, they’d work in your account too.
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 5, 2016, 12:33 p.m.
|
permalink
I think there is something wrong with my account. migrate does not work for me and errors out even when creating a new project.
Lluvian
|
29
posts
|
Sept. 6, 2016, 11:27 a.m.
|
permalink
What’s the exact command that you are running, and the error message?
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 6, 2016, 11:33 a.m.
|
permalink
./manage.py migrate
Unknown command: ‘migrate’
Type ‘manage.py help’ for usage.
./manage.py help
[auth]
changepassword
createsuperuser
[django]
check
cleanup
compilemessages
createcachetable
dbshell
diffsettings
dumpdata
flush
inspectdb
loaddata
makemessages
runfcgi
shell
sql
sqlall
sqlclear
sqlcustom
sqldropindexes
sqlflush
sqlindexes
sqlinitialdata
sqlsequencereset
startapp
startproject
syncdb
test
testserver
validate
[sessions]
clearsessions
[staticfiles]
collectstatic
findstatic
runserver
So I tried to install south but it states its installed. My next step was to add south to settings but then the application crashes.
Lluvian
|
29
posts
|
Sept. 6, 2016, 11:37 a.m.
|
permalink
Which version of Django and Python are you trying to use?
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 6, 2016, 11:39 a.m.
|
permalink
Also, can I take a look at your files? We can see them from our side, but we always ask permission first.
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 6, 2016, 11:40 a.m.
|
permalink
sure can. I just started and learning so I have no issues with it. I forgot to mention I will be going back to python 3.5 since you identified the issue was on my side.
Lluvian
|
29
posts
|
Sept. 6, 2016, 11:52 a.m.
|
permalink
OK, so it looks like you have a Python 3.4 project, which on PythonAnywhere right now will use Django 1.6. When you say «the application crashes» when you add south to settings, what exactly do you see?
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 6, 2016, 11:58 a.m.
|
permalink
It will show the stack trace of the errors but let me redo the project and try again.
Lluvian
|
29
posts
|
Sept. 6, 2016, 12:16 p.m.
|
permalink
So it worked like a charm. When I create a new app, do I just use ./manage.py createapp? Also, should I avoid using python before any command?
-Thanks
Lluvian
|
29
posts
|
Sept. 6, 2016, 12:30 p.m.
|
permalink
So it worked like a charm.
Great!
When I create a new app, do I just use ./manage.py createapp?
That’s right.
Also, should I avoid using python before any command?
You don’t need to use Python before any ./manage.py
command, and it’s generally safer not to.
The alternative is to make sure that you specify exactly which version of Python you want to use, which would be python3.4
for your current web app, but might be python3.5
or python2.7
if you create a new one with a different Python version.
The nice thing about not specifying it with the ./manage.py
command is that you don’t have to keep track of which particular Python version you used to create the web app. That’s because it’s already encoded in a «hashbang» line at the start of the file manage.py
.
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 6, 2016, 3:25 p.m.
|
permalink
So….
Problem: Between chair and keyboard.
Resolution: Educate the problem.
All jokes aside, I appreciate all the assistance you guys have provided me.
Lluvian
|
29
posts
|
Sept. 7, 2016, 11:44 a.m.
|
permalink
No problem, glad to help!
giles
|
11190
posts
|
PythonAnywhere staff
|
Sept. 7, 2016, 11:55 a.m.
|
permalink
random note- after you do ./manage.py createapp
, you also need to add that app to INSTALLED_APPS
in your settings.py
for django to see it.
conrad
|
4233
posts
|
PythonAnywhere staff
|
Sept. 7, 2016, 11:56 a.m.
|
permalink
.
RuntimeWarning: Got an error checking a consistent migration history performed for database connection 'default': could not connect to server: Connection refused
Is the server running on host «localhost» (127.0.0.1) and accepting
TCP/IP connections on port 5432?
how can i clear this error?
qualityfood
|
1
post
|
April 28, 2022, 7:25 a.m.
|
permalink