Questions tagged [django-mysql]
92 questions
                    
                    4
                    
            votes
                
                2 answers
            
        django.db.utils.OperationalError: (1091, "Can't DROP 'company_id'; check that column/key exists")
When I migrate, i always get it error. First, I created the table and then dropped it. Now when I created the table again. I am facing this issue. It also does not create the columns.
Model.py
class AssociateCompany(models.Model):
    user =…
         
    
    
        Carl Jordan Britto
        
- 69
- 1
- 2
                    3
                    
            votes
                
                0 answers
            
        Creating dynamic FIlter classes of JSONField attributes for Django admin
Let's consider below model as an example.
from django_mysql.models import JSONField
class Student(models.Model):
    standard = models.CharField(_('Standard'), max_length=10, null=True, blank=True, choices=STANDARD_CHOICES)
    extra =…
         
    
    
        Jay Modi
        
- 3,161
- 4
- 35
- 52
                    3
                    
            votes
                
                1 answer
            
        Django view returning count of users based on last_login
I have a Django application where I have a view that returns the count of the users who did login today. Corresponding statement is as follows:
login_count= User.objects.filter(last_login__startswith=timezone.now().date()).count()
I want to get the…
         
    
    
        Thinker
        
- 5,326
- 13
- 61
- 137
                    2
                    
            votes
                
                3 answers
            
        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 options looking at existing solutions but could not…
         
    
    
        Michael
        
- 8,357
- 20
- 58
- 86
                    2
                    
            votes
                
                1 answer
            
        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 avg_value
FROM djangoapp_somemodel
GROUP BY…
         
    
    
        Robert Berge
        
- 365
- 3
- 12
                    2
                    
            votes
                
                1 answer
            
        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.W004) django_mysql.models.JSONField is deprecated.…
         
    
    
        A.Motahari
        
- 173
- 5
- 10
                    2
                    
            votes
                
                1 answer
            
        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 created without def create_user_profile
and id…
         
    
    
        Naufal
        
- 89
- 2
- 8
                    2
                    
            votes
                
                0 answers
            
        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.Model):
        name =…
         
    
    
        aniline hates nazis and pedos
        
- 121
- 1
- 5
                    2
                    
            votes
                
                1 answer
            
        "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=True, blank=True)        
    def __str__(self):
 …
         
    
    
        rahnama7m
        
- 865
- 10
- 38
                    2
                    
            votes
                
                3 answers
            
        Django - Raw SQL Queries or Django QuerySet ORM
I know Django Object Relational Mapper (ORM) helps bridge the gap between the database and our code Performing raw queries. 
But I want to find out which is better - Raw SQL Queries or Django QuerySet ORM. 
So for that I was query on User Table…
         
    
    
        Cipher
        
- 2,060
- 3
- 30
- 58
                    2
                    
            votes
                
                2 answers
            
        Filter on JSONField array
I have a book model
class Book():
  ...
  tags=JSONField()
I have some records:
Book(..., tags=['TECH', 'BUSINESS'])
Book(..., tags=['MARKETING'])
I want to filter out the books that have tag 'Tech' or 'Business'
query = Q (
   …
         
    
    
        Quy Tang
        
- 3,929
- 1
- 31
- 45
                    2
                    
            votes
                
                2 answers
            
        Connect Django Project to a distant Mysql Database
I'm working on a Django Project on my localhost and I would like to use a distant MySQL Database.
My localhost IP is : 172.30.10.XX
My MySQL distant server is : 172.30.10.XX
In my Django settings.py file, I wrote :
DATABASES = {
    'default': {
   …
         
    
    
        Essex
        
- 6,042
- 11
- 67
- 139
                    1
                    
            vote
                
                0 answers
            
        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 mysqlclient
Collecting mysqlclient
  Using cached…
         
    
    
        Federico Tuñon Alves
        
- 11
- 1
                    1
                    
            vote
                
                1 answer
            
        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 = baseline * tan(angle). I am building a search…
         
    
    
        user1045680
        
- 815
- 2
- 9
- 19
                    1
                    
            vote
                
                0 answers
            
        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:
        with transaction.atomic():
           …
         
    
    
        motam
        
- 677
- 1
- 6
- 24