Questions tagged [django-database]

django-database refers to database backends that Django supports out of the box

django-database
Filter by
Sorted by
Tagged with
0 votes
1 answer
105 views

What is the simplest way to store a list of numbers in Django model without using third party databases

I want to store a list of numbers in Django model without using third party databases like MySQL, PostgreSQL etc. I want a simple approach. I don't think that there is any built-in field like ...
Anshul Gupta's user avatar
-1 votes
1 answer
252 views

model doesn't have migrations

I am working on the Django model. I migrate all the files of the app, but it is showing me the model doesn't have migrations and also no migration file in the folder, but init.py file exists in the ...
code 's user avatar
  • 25
-1 votes
1 answer
3k views

TypeError: Field.__init__() got an unexpected keyword argument 'max_lenght'

from django.db import models class Coustomer (models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) name = models.CharField(max_length=100) locality = models.CharField(max_lenght=...
Ash Prajapati's user avatar
0 votes
1 answer
33 views

How to add only the necessary model in django to the second database?

I use two databases in django, one is marked as "default", the other is optional. I have this question: I have a file with models, all these models are in the main database, and there is ...
Тв0р0бушек's user avatar
1 vote
1 answer
675 views

Django admin prefetch related on property

I have models Merchant and PhoneNumber. PhoneNumber has a foreign key to Merchant, and Merchant has property business_phone_number which fetches the first phone number in the set of the phone numbers. ...
TamaraB's user avatar
  • 95
0 votes
0 answers
233 views

i have a problem trying to connect to odbc

this is my dockerfile, or a fragment of where I'm trying to make the connection RUN apt-get update RUN wget https://www.openssl.org/source/openssl-1.1.1l.tar.gz -O openssl-1.1.1l.tar.gz && \ ...
Moisés Cantillo's user avatar
1 vote
1 answer
93 views

Django query if / else?

I'm building a website that displays photo albums. For that I have the following Models. class Medium(models.Model): pass class MediaSet(models.Model): media = models.ManyToManyField("...
JasonTS's user avatar
  • 2,559
1 vote
1 answer
1k views

Error while changing database engine to PostgreSQL

I got this error after changing the engine, the database is connected however it figured out my id field is a bigint, yet I specifically set it as a UUID field. class Cart(models.Model): id = models....
Keyvan Hosseini's user avatar
0 votes
1 answer
658 views

what way can i fix django DB migration error without deleting migration files

what is the best way to fix this kind of DataBase Errors without having to delete my db and migration files and starting to enter data from scratch? django.db.utils.IntegrityError: The row in table '...
Jephtah Jephtah's user avatar
0 votes
0 answers
166 views

Django Raw SQL relation does not exists

I am trying to execute raw sql but it requires a relation and I am not really sure where and why it doesnt work as it should. Settings.py 'default': { 'ENGINE': 'django.db.backends....
Hayato Hayato's user avatar
0 votes
1 answer
82 views

Django cannot save to to second database

I've tried using multiple database in my Django project. I create a model with foreign key to User but it can't save to second database. This is the UserData model: class UserData(models.Model): ...
Bintang1902's user avatar
1 vote
1 answer
381 views

Stripping down unnecessary apps from Django project

I want to remove all the unnecessary apps that come as default while creating a project in Django. My Project uses Auth0 for authentication and Firestore for database. I don't want the default ...
resun's user avatar
  • 35
1 vote
1 answer
252 views

How to apply select_related to the objects of a m2m relationship in Django? [duplicate]

Lets say there is a structure like this: class Aaaaa(models.Model): b = models.ManyToManyField('Bbbbb') class Bbbbb(models.Model): c = models.ForeignKey('Ccccc') class Ccccc(models.Model): ...
JasonTS's user avatar
  • 2,559
0 votes
1 answer
734 views

Django (proxy and abstract) add extra fields to child of a custom-user class (AbstrsactBaseUser)

I created a custom user class that is inherited from AbstractBaseUser, this class has a chil class. The problem is I can't add new fields to the children's classes because they had (class Meta: proxy =...
Emad's user avatar
  • 37
0 votes
0 answers
32 views

Different datetimes displayed in view and template in Django

When I display a datetime object in my template, the displayed result is a date very different from what I have in my database. Printing the datetime in the view for debbuging gives the same result as ...
jevisan's user avatar
  • 23
0 votes
1 answer
73 views

django "no such table" when adding database entries via terminal

I am trying to create a relational database (one to many) in my models.py file. But when trying to add entries into my database i get an error saying: django.db.utils.OperationalError: no such table: ...
logan_9997's user avatar
0 votes
2 answers
274 views

Foreign key is not assigned to a model in database

I recently started learning django and was making a CRM. models.py: class Complaint(models.Model): SOURCE_CHOICES=( ('email','E-mail'), ('call','Call'), ('ticket','Ticket') ) store_name=...
Kedar Raul's user avatar
0 votes
1 answer
39 views

How to fix issue saving form to django database?

So I have a form you can fill from the webpage which I want to save to my django database to create a new object when submitted instead of adding it in admin. I've tried it and the system works except ...
SKYZE's user avatar
  • 59
0 votes
2 answers
64 views

Set default value Django Models

I need to set a date to Enddate if the user didn't enter it by taking the value from Starting input, Let's say I have this Model: class DataSet(models.Model): Event = models.CharField(max_length=...
tibas's user avatar
  • 189
1 vote
1 answer
45 views

Fetching data from models using OneToOneField in Django

well my college is making us go learn a framework and make a website with it in a month, and it's really killing me, because of that I couldn't really get a good understanding of the Django framework ...
Bachar ELkarni's user avatar
1 vote
1 answer
225 views

Django admin prefetch content_type model

I used the django debug toolbar to analyse why the calls to my usermodel were so painfully slow within the django admin. There I saw that I had hundreds of duplicate calls to the content_type model: ...
Max B 0815's user avatar
0 votes
1 answer
235 views

Provide initial data for Django models from txt file

I have a .txt file with 3 columns (longitude, latitude, distance) and 40 million rows. These are the first lines of the file. -179.98 89.98 712.935 -179.94 89.98 712.934 -179.9 89.98 712.933 -...
Diego's user avatar
  • 68
0 votes
2 answers
3k views

MySQLdb._exceptions.OperationalError: (2002, "Can't connect to server on '<servername>.database.windows.net') | Django+Azure+MySql

I'm having issues connecting my Django app in my local machine to MySql Database in Azure? I added my IP in the Rules and am connecting with this: 'default': { 'ENGINE': 'django.db....
Anish's user avatar
  • 19
1 vote
1 answer
3k views

How to quickly reset Django DB after changes?

I'm often experimenting around creating different models, changing relations and so forth. This usually happens when starting a new project. At this phase I do not want to create any migrations but ...
JasonTS's user avatar
  • 2,559
0 votes
0 answers
243 views

Django .save() method not saving

I'm trying to save a text imput from an HTML page, and then display it on a redirect. It seems that the .save() method isn't working. I'm quite new to Django and HTML in general. I've followed the ...
Ian Milkó's user avatar
0 votes
0 answers
287 views

Connectivity issues to SAP SQL Anywhere database as a secondary database with Django

I can connect to a SAP SQL Anywhere database with FreeTDS and pyodbc as follows: # hello_sybase.py import pyodbc try: con = pyodbc.connect('Driver={FreeTDS};' 'Server=10.60.1.6,2638;'...
xralf's user avatar
  • 3,524
1 vote
1 answer
288 views

Django db_router does not exclude app models as expected

I am trying to create an application where one server communicates with many other worker servers. Those servers will each have their own DB which should only contain the tables for their own models. ...
Tary's user avatar
  • 65
1 vote
1 answer
548 views

How to change the database local to be in a cloud (Django)

I wrote a project in django framework and I use the local DataBase SQLite, and I now want to upload it to the cloud so other people who work with me can access DataBase i.e. when I create a user then ...
OmerBY's user avatar
  • 177
0 votes
0 answers
274 views

How to create different database tables for user types in Django?

Here is what I am trying to do. The project has Two Type of users: Spot Owners Spot Rentee Owners can add slot, Rentees can book slot. Here is my code: models.py: class UsersManager(BaseUserManager):...
Tanjim Hudai's user avatar
0 votes
0 answers
281 views

Does changing Django database backend require code modification?

I'm currently using sqlite3 as Django database backend. However I'm looking forward to use MySQL in the future. Does changing database backend require source code modifications such as models.py, ...
47-54-50-56's user avatar
-1 votes
1 answer
777 views

OperationalError at /admin/ route of django project [duplicate]

Hey I work with django framework I had the error OperationalError. I have two classes with the same fields: class Student(models.Model): user = models.OneToOneField(User, null=True, blank=True, ...
OmerBY's user avatar
  • 177
0 votes
1 answer
267 views

Update Database column after every 30 days in django

I am creating a Django application where my requirement is that for each user I have a boolean value which is set to False by default. Now if the user completes a particular task then the value change ...
Tushar Sethi's user avatar
0 votes
1 answer
38 views

How to deal with lots of duplicated data in DB?

I'm currently building a database for a photography project and I'm having troube to decide this: There are about 3 million photographs and I'd like this to keep working even with 15 million. They are ...
JasonTS's user avatar
  • 2,559
0 votes
1 answer
885 views

Django custom field change not detected by migrations

I have multiple custom fields in Django. First, they extended PositiveSmallIntegerField as we used int choices like: class BusinessLegalFormField(models.PositiveSmallIntegerField): choices = [(1,'...
Milano's user avatar
  • 18.5k
0 votes
0 answers
184 views

malloc error when migrate in Django using mySQL database

I'm using Django in VSCode and want to connect to the MySQL database, I've created the database in MySQL. When changing the database configuration from mysqlite to MySQL in settings.py, and do the ...
user16202700's user avatar
1 vote
2 answers
323 views

how do increment all column values in db table after certain integer values in that column (django)?

Suppose I have created "X" database table in Django which has column id(autofiled), name(charfield) and occurrence(integerfield), now suppose 3 rows are already available in it id name ...
shraysalvi's user avatar
0 votes
1 answer
34 views

Sum of two calculated annotation in django

.annotate( waste=Sum("processings__chunks__waste"), completed_waste=models.Task.get_completed_waste_annotation(), tooling_time=Sum("...
Stefano's user avatar
  • 3,167
0 votes
3 answers
88 views

How can I receive a list of dictionaries in djano?

Hello I am working on a djago project and I want to recieve a list of dictionaries just like this: [{1: 20}, {2:30}, {3: 50}, ......] here the key is the id of the productand value is price And the ...
user avatar
0 votes
1 answer
749 views

django save method not changing attribute

Trying to use the save method to change the admin =True, on a user. But it is not changing. User models class User(AbstractBaseUser): email = models.EmailField( verbose_name='email address'...
MerrinX's user avatar
  • 183
2 votes
1 answer
397 views

Django converting isoformat string datetime to tuple and rising error

I'm trying to update two datetimefields for the Skill entity in my db. I'm sure I'm passing an isoformat datetime string. When creating instead of updating everything works fine but on the update I ...
FrancescoManfredi's user avatar
0 votes
2 answers
10k views

Get data from django database model

I have a django model, PhoneNumberVerification. It has two columns: phone number, and code. I want to be able to get the code if I am given a phone number. Essentially, search the table for which row ...
Datajack's user avatar
  • 140
0 votes
1 answer
376 views

how to automatically update daily datetime in django

Hi I want to automatically update datetime daily in my database and put the today date as now then it show the subtract the start day and no and give me the delta is there any way to do this?
Amin's user avatar
  • 34
1 vote
1 answer
573 views

django connect remote postgresql

Trying to connect to a remote server, serving my posgresql My settings.py DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydatabase', ...
MerrinX's user avatar
  • 183
1 vote
1 answer
3k views

save() prohibited [...] due to unsaved related object, but related object already saved

I'm working with Django 4.0.1. I'm having having "save() prohibited to prevent data loss due to unsaved related object 'page'" even if the 'page' object is saved one line before. Here is the ...
FrancescoManfredi's user avatar
0 votes
0 answers
112 views

Question regarding HTML form action attribute

I have used Django to set up the backend of a web app and have an HTML form I am using as a signup page and was wondering if there's anything I need to add to the Forms' form action attribute. What I ...
David_Codes's user avatar
1 vote
0 answers
103 views

Two projects using the same Django database. Who should create the tables?

I have two Django projects that need to use the same postgres database. I created the database in one of the projects -- no problems; I just created the second project. It will need access to tables ...
Andrew's user avatar
  • 149
0 votes
2 answers
610 views

I am trying to get data from database using python Django but got an error

Hello everyone I am trying to get data from database but it give me error in case when I am trying to get single data from db as shown below wahid = Webapp.objects.get(title="Ecommerce Website&...
Wahid Hussain Turi's user avatar
0 votes
1 answer
59 views

Temporary model instances referenced as foreign keys

Is there a way to keep a Django model instance, which is referenced by foreign keys, in memory without storing it to the database? The code is part of an _add_ overload, but the way it is implemented ...
Boketto's user avatar
  • 737
0 votes
2 answers
45 views

Count foreignkey objects in django

suppose class Product(models.Model): user = models.ForeignKey(User,...) ... class Sold(models.Model): post = models.ForeignKey(post,...) buyer = models.ForeignKey(User,...) Now how ...
RoyalBosS's user avatar
  • 380
1 vote
1 answer
29 views

How to choose one item in many to many relationship as special?

What is the best practice to choose one item from a m2m relationship? Lets say I've got an album of photos: class Photo(models.Model): img = models.FileField() class Album(models.Model): photos = ...
JasonTS's user avatar
  • 2,559

1
2
3 4 5
14