Getting Django - MySQLdb._exceptions.OperationalError: (1025, 'Error on rename of ) - django

I am trying to connect my Django project to mariaDB but I am getting error
MySQLdb._exceptions.OperationalError: (1025, 'Error on rename of \'./mydb/auth_permission\' to \'./mydb/#sql-backup-13c39-4a\' (errno: 168 "Unknown (generic) error from engine")')
I tried removing the foreign keys and dropping the table but it still does not work. Tried this solution as well https://confluence.atlassian.com/confkb/mysql-error-1025-thrown-when-attempting-to-change-table-collation-and-character-set-785332187.html
but had no effect at all.

Related

Django password reset with MongoDB - DatabaseError with no exception message

I've connected my Django app with MongoDB, register/login/logout are all working fine. But when I use the Django default password reset email it throws a database error.
What I've tired:
sqlite3 - register/login/logout (Working)
MongoDB - register/login/logout (Working)
sqlite3 - password reset email (Working)
MongoDB - password reset email (NOT Working)
I was able to land on the Django password reset page, but when I hit confirm it return the error on the browser
DatabaseError at /pw_reset/
No exception message supplied
Request Method: POST
Request URL: http://localhost:8000/pw_reset/
Django Version: 3.2.6
Exception Type: DatabaseError
Exception Location:
C:...venv\lib\site-packages\djongo\cursor.py, line 59, in execute
The above exception ( Keyword: None Sub SQL: None FAILED SQL: ('SELECT "accounts_user"."id", "accounts_user"."password", "accounts_user"."last_login", "accounts_user"."is_superuser", "accounts_user"."username", "accounts_user"."first_name", "accounts_user"."last_name", "accounts_user"."email", "accounts_user"."is_staff", "accounts_user"."is_active", "accounts_user"."date_joined" FROM "accounts_user" WHERE ("accounts_user"."email" iLIKE %(0)s AND "accounts_user"."is_active")',) Params: (('test#test.com',),) Version: 1.3.6) was the direct cause of the following exception:
Console log:
Traceback (most recent call last):
File "C:...\lib\site-packages\django\template\base.py", line 850, in _resolve_lookup
(bit, current)) # missing attribute
django.template.base.VariableDoesNotExist: Failed lookup for key [name] in <URLResolver <URLPattern list> (admin:admin) 'admin/'>
URL Path:
path('pw_reset/', auth_views.PasswordResetView.as_view(), name="reset_password"),
The Views I defined myself (register/login/logout) are all working fine. But the built-in one PasswordRestView is not. I've tried dropping the DB, reinstall djongo, I run out of ideas... Please help!
Fixed by downgrading versions on:
Django==3.0.5
djongo==1.3.4
sqlparse==0.2.4

Error creating new content types when Uwsgi kills a worker

I am Running a django application with uwsgi, I am observing a case Sometimes, when uwsgi kills it's worker and and respawns a worker.
Thu Aug 8 11:02:33 2019 - worker 1 killed successfully (pid: 25499)
Thu Aug 8 11:02:33 2019 - Respawned uWSGI worker 1 (new pid: 4192)
And then the next request received by the django application returns 500 error with Exception:
RuntimeError: Error creating new content types. Please make sure contenttypes is migrated before trying to migrate apps individually.
at line
content_type = ContentType.objects.get_for_model(Coupon)
EDIT:
Django version: 1.8.6
Uwsgi Version: 2.0.12
ISSUE
I went through multiple sources and Content Types code, I found the reason for this case.
The Error occurred on this line
content_type = ContentType.objects.get_for_model(Coupon)
here, get_for_model method first fetches the object from cache. If it fails, it gets from DB, else creates the record in DB.
In my case, the Connection to DB was disrupted leading to OperationalError and for this error it raises RuntimeError with the Error description mentioned in question.
The same Error can also be returned in case of IntegrityError or ProgrammingError.
OperationalError
Exception raised for errors that are related to the database's operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc. It must be a subclass of DatabaseError.
IntegrityError
Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails. It must be a subclass of DatabaseError.
ProgrammingError
Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc. It must be a subclass of DatabaseError.
Snippet from Django 1.8.6 Source-code:
def get_for_model(self, model, for_concrete_model=True):
"""
Returns the ContentType object for a given model, creating the
ContentType if necessary. Lookups are cached so that subsequent lookups
for the same model don't hit the database.
"""
opts = self._get_opts(model, for_concrete_model)
try:
return self._get_from_cache(opts)
except KeyError:
pass
# The ContentType entry was not found in the cache, therefore we
# proceed to load or create it.
try:
try:
# We start with get() and not get_or_create() in order to use
# the db_for_read (see #20401).
ct = self.get(app_label=opts.app_label, model=opts.model_name)
except self.model.DoesNotExist:
# Not found in the database; we proceed to create it. This time we
# use get_or_create to take care of any race conditions.
ct, created = self.get_or_create(
app_label=opts.app_label,
model=opts.model_name,
)
except (OperationalError, ProgrammingError, IntegrityError):
# It's possible to migrate a single app before contenttypes,
# as it's not a required initial dependency (it's contrib!)
# Have a nice error for this.
raise RuntimeError(
"Error creating new content types. Please make sure contenttypes "
"is migrated before trying to migrate apps individually."
)
self._add_to_cache(self.db, ct)
return ct
SOLUTION
I need to upgrade my Uwsgi to or above 2.0.14 as before this version, Uwsgi kills any old worker to only give resources to Cheap Workers.

Python Sqlite3 attaching to a memory database

I am using Python 2.7 with sqlite3 version 2.6.0. I am trying to create a memory database, attach to it from a physical database and insert data, then query it back later. I am having issues if anyone can help.
The following two fail with the error message "unable to open database file"
con = sqlite3.connect(":memory:?cache=shared")
con = sqlite3.connect("file::memory:?cache=shared")
The following works until I attempt to access a table in the attached DB. I can do this with physical databases with no problem. I suspect the issue is not having the cache=shared.
con = sqlite3.connect(":memory:")
cursor = con.cursor()
cursor.executescript("create table table1 (columna int)")
cursor.execute("select * from table1")
con2 = sqlite3.connect("anotherdb.db")
cursor2 = con2.cursor()
cursor2.execute("attach database ':memory:' as 'foo'")
cursor2.execute("select * from foo.table1")
The error from the last select is "no such table: foo.table1".
Thanks in advance.
The SQLite library shipped with Python 2.x does not have URI file names enabled, so it is not possible to open an in-memory database in shared-cache mode.
You should switch to apsw, or Python 3.

Symfony PostGIS - db reverse engineering

situation:
Symfony 3.2
jsor/doctrine-postgis 1.3 - configured with service and required data type in config
PostgreSQL database with PostGIS extension.
Two schemas:
geo
sch1
Schema geo has tabels with geometry.
Schema geo has postgis extension.
Schema geo has views geometry_columns and etc
when I try to run
./bin/console doctrine:mapping:import --force GeoBundle xml
I get errors
[Doctrine\DBAL\Exception\TableNotFoundException]
An exception occurred while executing 'SELECT coord_dimension, srid, type
FROM geometry_columns
WHERE f_table_name = ?
AND f_geometry_column = ?' with params ["boisko", "geom"]:
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "geometry_columns" does not exist
LINE 2: FROM geometry_columns
&
[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "geometry_columns" does not exist
LINE 2: FROM geometry_columns
&
[PDOException]
SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "geometry_columns" does not exist
LINE 2: FROM geometry_columns
I wonder if anybody had similar problem and could help me out to sort it.
problem was search_path
as soon I set it up everything works as expected

Python 2.x unicode & pymssql

I want to upload a string in unicode to my sql server. I'm using python 2.7.6, sqlalchemy-migrate 0.7.2, pymssql 2.1.2.
But when I saved my object I got an OperationalError from sqlalchemy
OperationalError: (OperationalError) (105, "Unclosed quotation mark
after the character string '\xd8\xa3\xd8\xb3\xd8\xb1\xd8\xa7\xd8\xb1
\xd8\xaa\xd8\xad\xd8\xaf\xd9\x8a\xd8\xaf\xd8\xa7\xd9\x84\xd9\x88\xd8
\xac\xd9\x87 - \xd9\x81\xd9\x82\xd8\xb7 \xd9\x84\xd8\xaf\xd9\x89\xd9
\x85\xd8\xad\xd9\x84\xd8\xa7\xd8\xaa \xd9\x88\xd8\xac\xd9\x88\xd9\x87
\xe2\x9c\x8e '.DB-Lib error message 105, severity 15:\nGeneral SQL
Server error: Check messages from the SQL Server\n") 'INSERT INTO...
With more detail I'm guesssing is from my Description value :
...\u0648\u062c\u0648\u0647 \u270e \U0001f38'}
I saw a big U and not u, the character is the gift unicode just before, the "\u270e" works well and show a pencil. I strongly thing is because of the 8 values versus 4 for others.
But how to prevent this error ?
The column description inside of my DB is a nvarchar(2000)
I'm using Using flask restful reqparse to parse the argument create sync the object from the DB and save it :
parser_edit.add_argument('Name',
type=unicode,
required=True,
location='json')
parser_edit.add_argument('Description',
type=unicode,
required=False,
location='json')