Django database authentication plugin error - python

I had a Django project that I had worked on in the past for quite a while. Recently, I tried to reopen it and add some minor changes. What happened is that recently I also reinstalled MySQL(8.0) and of course, recreated my old database. But now when I tried to run the server or any other operation, I get the following error:
2059, "Authentication plugin 'caching_sha2_password' cannot be loaded: The specified module could not be found.
I tried the solution from other post, but it did not work for me. Here is also a full traceback of the error: https://pastebin.com/JqexqTtC

I had the same problem and I fix this issue with the first method:
If you have access to database through workbench, mysql console... and you have permission to alter user so you can change auth_plugin for default
ALTER USER 'your_user' IDENTIFIED WITH mysql_native_password BY 'your_password';
If you don't have permission to it database so you can change mysql connector.
add link: https://www.codegrepper.com/code-examples/sql/raise+errors.NotSupportedError%28+mysql.connector.errors.NotSupportedError%3A+Authentication+plugin+%27caching_sha2_password%27+is+not+supported

Related

Django: Unknown column error when running on production server

When I try to access my Django application on the production server (AWS EBS), it keeps returning the following error (1054, "Unknown column 'two_factor_phonedevice.throttling_failure_timestamp' in 'field list'").
Strangely, the app works fine when running locally using the exact same MYSQL database (AWS RDS) and settings.
I have tried dropping the database and re-running migrations believing it was due to an inconsistency between my db and migrations files however I still keep getting the same error.
I am using the django_two_authentication module for the user authentication/logins. The table two_factor_phonedevice is created by the module to track the user devices registered for two factor authentication.
I cannot seem to solve why the column can be found when running locally but cannot be found on the production server despite both using the same database.
I am not familiar with django_two_authentication specifically, but I would check the different settings module you are using in each environment.
You may have differences in the INSTALLED_APPS or some other relevant entry.
Turns out the module version was not specified in the production requirements.txt file meaning the newest version (which happened to have a different db schema) was installed by default causing different versions to be running locally and in production environments.
To resolve this I explicitly set the module version in the requirements.txt file to match that of the local one.

Django bulk_create with ignore_conflicts=True giving ProgrammingError

I am getting this strange error
ProgrammingError at /save_hsn/
syntax error at or near "ON"
LINE 1: ...021-01-28T06:17:43.784614+00:00'::timestamptz, 1) ON CONFLIC...
this is my views.py part where I am getting the error
user_gst_codes.objects.bulk_create(hsn_list, ignore_conflicts=True)
If I remove ignore_conflicts=True, everything works.
Moreover, I start getting this error after deploying my Django app on cPanel, on localhost this doesn't give any error.
On localhost-
Python 3.6.6, Django 3.1
On cPanel-
Python 3.6.11, Django 3.1
Is this an issue with the Python version?
I am inserting data in bulk and also need to keep the unique check.
Any help would be appreciated.
Notice that the ON CONFLICT clause is only available from PostgreSQL 9.5. If you are using an earlier version, you will need a workaround to have the upsert feature. Please check local postgresql version and server postgresql version.

Strange error during initial database migration of a Django site

I have been working on a localhost copy of my Django website for a little while now, but finally decided it was time to upload it to PythonAnywhere. The site works perfectly on my localhost, but I am getting strange errors when I do the initial migrations for the new site. For example, I get this:
mysql.connector.errors.DatabaseError: 1264: Out of range value for
column 'applied' at row 1
'applied' is not a field in my model, so this error has to be generated by Django making tables for its own use. I have just checked in the MySQL manager for my localhost and the field 'applied' appears to be from the table django_migrations.
Why is Django mishandling setting up tables for its own use? I have dropped and remade the database a number of times, but the errors persist. If anyone has any idea what would cause this I would appreciate your advice very much.
My website front end is still showing the Hello World page and the Admin link comes up with a page does not exist error. At this stage I am going to assume this is related to the database errors.
EDIT: Additional information about why I cannot access the front-end of the site:
It turns out when I am importing a pre-built site into PythonAnywhere, I have to edit my wsgi.py file to point to the application. The trouble now is that I don't know exactly what to put there. When I follow the standard instructions in the PythonAnywhere help files nothing seems to change. There website is also seems to be very short on detailed error messages to help sort it out. Is there perhaps a way to turn off their standard hello world placeholder pages and see server error messages instead?
As it says in my comment above, it turns out that the problem with the database resulted from running an upgrade of Django from 1.8 to 1.9. I had forgotten about this. After rolling my website back to Django 1.8, the database migrations ran correctly.
The reason why I could not access the website turned out to be because I had to edit the wsgi.py file, but I was editing the wrong version. The nginx localhost web server I was using keeps it in the different folder location than PythonAnyhwere's implementation. I uploaded the file from my localhost copy and edited it according to the instructions on PythonAnywhere's help system without realizing it was not being read by PythonAnywhere's server. What I really needed to do was edit the correct file by accessing it through the web tab on their control panel. Once I edited this file, the website front end began to work as expected.
This issue occurred for me as well on version 1.10 with a brand new project. I found that if you use the recommended driver and the connector in the documentation, the migration works without issues.
If you don't feel like reading the docs, in breif:
Install MySQLdb for python 2.7 or mysqlclient for python 3.3+
Modify your settings.py file. In the DATABASES dictionary set:
'ENGINE': 'django.db.backends.mysql',

sqlite3 -- can't open database file

For background, I'm trying to migrate my sqlite3 local db to a postgresql db on Heroku.
I have no problem accessing the db locally through my (Django) development server. However, when I try to push the db to Heroku, it says it can't open the file.
heroku db:push sqlite://path/to/db --confirm my-app-name
I get the following message:
Loaded Taps v0.3.23
Warning: Data in the app 'my-app-name' will be overwritten and will not be recoverable.
Failed to connect to database:
Sequel::DatabaseConnectionError -> SQLite3::CantOpenException: could not open database: unable to open database file
Most everything I've seen on Google relates to some bugs in earlier versions of Tap. Otherwise, I'm not sure what I should do here.
I've tried following the advice of this question and others about permissions, but I have full read and write access to the file and containing folder. I'm not too experienced with permissions -- do I need to switch ownership of the db to another user?
If /path/to/database is an absolute path, you need to do:
heroku db:push sqlite:///path/to/db --confirm my-app-name
Note the third slash. It could also be a permissions issue, in which case you want to either change the owner to the current user, or give at least read permission to the database (644).
I would try to save the data from sqlite3 to a fixture via dumpdata and then, after switching to postgres, load it again via loaddata.

Django unable to open sqlite on SOME queries only?

I have had no troubles locally, but pushing a new project to an existing machine (one running plenty of other django apps without trouble) gave this:
OperationalError: unable to open database file
What is more perplexing is:
The sqlite file is read-write for all
This error only happens on some queries! Other's are fine.
In a fresh db after running syncdb, my views work, but /admin/ triggers this.
If I loaddata for some of my apps from data dumped from my local machine, some of the apps trigger this in my views, and others do not.
I can find no correlation between any of the things that seem to trigger this.
Why would it fail to open the database, aside from permissions?
Write access on the directory. I thought i checked that first :-/

Categories