90 questions
-1
votes
1
answer
36
views
how to mysql database in django project
i set database connecting statement in settings.py it returns
no biulding tools and ask to install mysqlclient.
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you ...
0
votes
1
answer
3k
views
Accessing MySQL database with Django
Apologies in advance if this type of question already exists with a solution. I have been trying to get this solved for about 2 weeks now.
So I had a Django project, which initially used the default ...
0
votes
2
answers
91
views
Django SELECT Query
Hi Iam try to select from mysql using Django
my models.py
from django.db import models
from django.db.models import Q
class Series(models.Model):
id = models.IntegerField(primary_key=True)
...
0
votes
1
answer
97
views
Error when trying to delete model instance in Django 4.2.2
I've been trying to delete an existent instance from the user table (mysql) but I keep getting error from the user.delete()
this is the my viewpoint:
@api_view(['GET', 'PUT', 'DELETE'])
def ...
0
votes
1
answer
211
views
Django LIKE operation
I'm trying to send a query through Django python
I also try to block any sql injection exploits
Can someone explain to me how messaging is done
LIKE Query
for example
"SELECT * FROM admin WHERE ...
0
votes
1
answer
85
views
Redirect database call to different db url based on type of query(Read, write, update) with Django
In an existing project, how can I implement a method using which I can redirect it different database(Write, Update & read) without modifying existing Django queries?
If I have 2 queries:
MyModel....
0
votes
0
answers
734
views
I need a simple python Django login example using database credentials
Could you please help me find an example of a simple login page where the users can be authenticated using user/password from a database postgres or mysql(I can change that afterwards from mysql to ...
0
votes
0
answers
322
views
Django - MySQL (1170, "BLOB/TEXT column 'my_column' used in key specification without a key length [duplicate]
I've updated the Django model field from CharField to TextField.
I got the below error while applying migrations in MySQL.
django.db.utils.OperationalError: (1170, "BLOB/TEXT column 'my_column' ...
1
vote
0
answers
93
views
Install mysqlclient for Django in MacOs
I try to run "pip3 install mysqlclient" on macos for an app in django and it gives me this error.
I'm using a venv virtual environment, the python version used is 3.10.5
pip3 install ...
3
votes
3
answers
2k
views
Django with MySQL: 'Subquery returns more than 1 row'
Using django with a MySQL DB and given these models:
ModelB ---FK---> ModelA
- ref_type
- ref_id
ModelC
I want to get all the ModelC for each ModelA via an annotation.
I tried many ...
0
votes
1
answer
90
views
Efficient way to re-order objects in Django
I have written a query to re-order objects based on the values I get in the API request.
Below is the sample code I have written:
@action(detail=False, permission_classes=[], methods=["PUT&...
1
vote
1
answer
98
views
Django Query Annotation Does Not Support math.tan() Calculation
I have a django 3.2/mysql website. One of the tables, Flights, has two columns, angle and baseline. These two columns are combined in a view to display the value altitude using the formula altitude = ...
1
vote
0
answers
328
views
Handle deadlock in django with corrupted savepoint
I have an unavoidable bulk_create deadlock in my code. I decided to handle this part inside an atomic block and re-issue transaction when deadlock happened. Something like this:
while True:
try:
...
1
vote
2
answers
2k
views
Django MySQL - Setting an index on a Textfield
I have a database of articles that I want to search through. I had been using normal Django ORM to search, which was getting way to slow and then I got to know a little about Indexes in Django. I'm ...
2
votes
1
answer
148
views
How can I rewrite an average value per date time interval MySQL query as a Django QuerySet?
I have the following MySQL query that displays the average value per 10 minute interval:
SELECT FROM_UNIXTIME(FLOOR(UNIX_TIMESTAMP(date_time) / 600) * 600) AS interval_date_time,
AVG(some_value) AS ...
1
vote
0
answers
123
views
Empty QuerySet in django-mysql JSONField
When I am executing
ModelName.objects.filter(firstName__contains="MyName")
it returns an empty queryset but when I am executing it's SQL equivalent in dbshell it is fetching the rows ...
1
vote
0
answers
287
views
Django constraint: allowing 1 field to only have a single combination with another field while still alowing historical data
I am trying to create a constraint on my Offer table, which has an offer_id (charfield) and a product_id (foreign key) where an offer_id can only be combined with 1 product. It is not allowed that an ...
1
vote
1
answer
3k
views
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position 180: invalid start byte
I'm using Django with below config in settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '-',
'USER': '-',
'PASSWORD': '-',
...
0
votes
0
answers
525
views
Connect remote mysql to django
i have a MySQL database in cpanel and i want to connect my django project to this database when i try to connect it it show a message that i can't connect to localhost but i don't want to connect to ...
0
votes
0
answers
539
views
Django migrate from sqlite3 to mysql
I am trying to migrate my Django app from SQLite3 to MySql. I took following steps
Configured a new empty database on MySql. I did not create any tables because I assumed that the tables will be ...
0
votes
1
answer
720
views
How to Load a .dump File Format Using manage.py loaddata in Django?
I have a data.dump file for mysql and am trying to use manage.py loaddatato fill my db with this data file, but getting this error:
CommandError: Problem installing fixture '˜/Downloads/data': dump is ...
1
vote
2
answers
1k
views
JSON data saving using Django 3.3
As we know, Django=3 is supporting JSONField .
I am trying to save JSON data in my Django Project using JavaScript, i have take data in a input field which looks like:
[{"id":1,"Name&...
1
vote
1
answer
407
views
I can't start gunicorn on AWS EC2
I was going to update to using sqlite database into the mysql database on my django project.
after replaced settings.py like bellow:
` DATABASES = {
'default': {
'ENGINE': 'django.db....
1
vote
1
answer
385
views
How to use default-character-set in django - mysql database connection
So, I was re-configuring my SQL and decided to move back from my.conf to settings.py (context: https://docs.djangoproject.com/en/3.2/ref/databases/#mysql-notes)
'read_default_file': '/path/to/my.cnf',...
2
votes
1
answer
9k
views
JsonField in Django for MySQL
I currently use django 3.2 and MySQL as database, I want use MySql Json Field. For this reason use django-mysql third party package in my project.
After create model got this Warning: (django_mysql....
0
votes
1
answer
874
views
Django Annotate ExpressionWrapper Does not Return Expected Type
I have the following models:
class Creditor(models.Model):
terms_of_payment = models.IntegerField(
blank=False,
null=False
)
class Invoice(models.Model):
creditor = models....
1
vote
1
answer
1k
views
Multiple databases in same MySQL server
I already have and database in MySQL for my one Django project.
I need to make two separate Django projects share the same database.
project1/settings.py:
DATABASES = {
'default': {
'...
0
votes
1
answer
224
views
How to prevent mySQL autoincrement from resetting in Django
I am creating a Django app where the primary keys are AutoFields. i.e. I am not manually assigning any field as primary key in my models.
I need to use mySQL.
I will need to export all the data to ...
1
vote
1
answer
158
views
Compare mutiple ids present in list of dictionaries with the ids of model django
How can i make an efficient django orm query, which will compare ids from the list of dictionaries with the ids as foreign key in other model, e.g i have two models
Product:
product_name=models....
0
votes
1
answer
300
views
Connect Django to MySql database on VPS
I am trying to run my Django project on a VPS. My Django project uses MySQL. While running it on my local computer I used the following code to connect MySQL to Django
DATABASES = {
'default': {
'...
0
votes
1
answer
273
views
How to use mysql-connector mysql adapter with django??/
I cannot use mysqlclient package in the hosting server because it is a shared hosting server and they would not let me have a root privilige!! so I found about the mysql-connector adapter, I guess it ...
0
votes
1
answer
1k
views
ValueError: source code string cannot contain null bytes in django while running python manage.py migrate after inspectdb
I connected my Django with mysql database and ran a sql script to make a database and ran migrations on my django project and I had no errors but to to use the database I had to use python manage.py ...
0
votes
0
answers
152
views
Python - Django, Cannot install mysqlclient using pip
I'm new to Django and I'm facing some issues installing mysqlclient for my application running this command
pip install mysqlclient
I'm getting an error ModuleNotFoundError: No module named 'pip....
1
vote
1
answer
660
views
Django QuerySet.update() fails on MySQL if a subquery references the base table
I am trying to make this transaction mysql compatible. As mysql don't allow the current operation. MySQL doesn't allow updating the table you are already using in an inner select as the update ...
2
votes
1
answer
85
views
my user_id profile database is null, how i insert the value in user_id?
Why does my data look like this?
can i make the value in user_id?
if i delete the def create_user_profile it will create nama, nik, email, nomor_hp.
but user_id is null
in the picture, id 1 and 2 i ...
0
votes
1
answer
559
views
Is it possible to connect local django project to MySql running on AWS EC2? How?
What I tried:
Installed the MySql server on the EC2 instance.
In the security group of the instance added an inbound rule to connect over shh from all source
Created a database and user
Given that ...
0
votes
1
answer
113
views
Generic way to perform CURD operation
I am new to the Django framework. I want to create generic controller which can accept body as follows
{
"operation":"select",
"fields":["user_id","user_name","user_email"],
"table":"user"...
0
votes
2
answers
1k
views
Django MySQL Database location and setup
So I have a MySQL database for my Django project which I think is located in the default directly (wherever that should be). When I want to move my Django project to digital ocean, how do I move that ...
0
votes
1
answer
71
views
Unable to delete the data from mysql table which is fetched from a form in HTML using Django
I am want to:
1. save data from a HTML form to MySQL
2. delete data from mySQL which is entered through HTML form.
The save functionality is working. While there is error in delete functionality.
...
0
votes
1
answer
2k
views
Django ForeignKey from external Database
I'm working with 2 Databases, 1 external not managed by Django and the other internal.
Thi is the external database now working on models and in Admin site:
class Client(models.Model):# IMPORT FROM ...
0
votes
1
answer
1k
views
Creating models.UniqueConstraint in django, but the constraint is not applying
My table is defined as below.
class Role(models.Model):
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
to_field="email",
db_column="user",
on_delete=models....
0
votes
2
answers
109
views
How to Insert & Update Multiple Record in Django
I want to know how to deal with this task.
here are the details:
this is product_feature model
class Feature(models.Model):
has_value_choice = [
('y', 'Yes'),
('n', 'No'),
]
...
0
votes
2
answers
101
views
Adding data to many-to-many relation in Django database
I am using django 2.2, python 3.6.8 on ubuntu 18.04 with mysql server.
I have courses, student and courses_student tables.
There is a many-to-many relation between courses and students.
In Courses ...
0
votes
0
answers
253
views
Setting a field as primary key in django model
I am using django 2.2 with python 3.6.8 on ubuntu 18.04.
I created a model like below :
@reversion.register()
class Courses(BaseModel):
coursecode = models.AutoField(primary_key=True, ...
0
votes
1
answer
192
views
Column is not being added to table Mysql using Django
The following diagram is from my database
Database schema
I have the following model that represents that schema:
class Finalproduct (models.Model):
idfinalproduct = models.AutoField(...
1
vote
2
answers
896
views
Is there a better way to store a list of integers in a MySQL Model?
I'd like to store a list of integers in a MySQL field.
My current workaround:
import datetime
from django.db import models
class myModel(models.Model):
testList = models.CharField()
def ...
2
votes
0
answers
124
views
Annotation field is str instead of datetime.datetime
Example
I'm trying to annotate objects using data from a related model's DateTimeField.
class Author(models.Model):
name = models.CharField(max_length=256)
class Book(models....
0
votes
1
answer
2k
views
ArrayField In Django is giving error while doing migrations
I have added arrayfield to model in my application. Below is my model
class employees(models.Model):
firstName=models.CharField(max_length=10)
lastName=models.CharField(max_length=10)
...
0
votes
0
answers
34
views
model overwrites another model
I have made a table "Offenses" in my database which works fine, it has a primary key named "id"
Now i want to create another table with name offense_category. and want to create a foreign key that ...
2
votes
1
answer
9k
views
"BLOB/TEXT column used in key specification without a key length" error in Django
I have this model in my Django project:
class Institution(models.Model):
name = models.CharField(unique=True, max_length=100, blank=True)
description = models.TextField(max_length=500, null=...