Questions tagged [django-database]

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

refers to database backends that Django supports out of the box.

This tutorial help you to make application using mongodb database. enter link description here

664 questions
7
votes
1 answer

Insert an list in Django 1.9.2 database sqlite3

I want to store a list in database of Django .which model field i should use and how. I tried ArrayField but it does not take list. from django.contrib.postgres.fields import ArrayField from django.db import models class signup(models.Model): …
Kunal Kakade
  • 107
  • 2
  • 10
7
votes
2 answers

How to run a management command in django views.py

I'm going to use django-dbbackup in my current application. My task is to take backup of my latest sqlite3 database with custom_name.db when 'Backup Database' button is pressed from the UI and to restore a backup from a list of existing backups when…
Rafiul Sabbir
  • 626
  • 6
  • 21
7
votes
1 answer

Django & Soft Deletion: Implementation architecture

Definitions SOFT DELETE - does not remove an object from the database, but appears to do so HARD DELETE - removes the object completely from the database Question What is the best way to implement soft deletion in a codebase (specifically, a…
jvc26
  • 6,363
  • 6
  • 46
  • 75
6
votes
1 answer

Django and PostgreSQL - value too long for type character varying(512)

I am migrating from a test SQLite database to a PostgreSQL database. I have a sample object that is inserted in the database, that worked on SQLite but is giving me an error in PostgreSQL. Code snippet is: car = CarItem.objects.create( user =…
user1034697
6
votes
1 answer

'unique_together' refers to the non-existent field

When trying to use unique_together on two foreign key constraints, I get the following error: CommandError: System check identified some issues: ERRORS: main.AuthorTag: (models.E012) 'unique_together' refers to the non-existent field…
evrom
  • 93
  • 1
  • 5
6
votes
2 answers

Django : Call a method only once when the django starts up

I want to initialize some variables (from the database) when Django starts. I am able to get the data from the database but the problem is how should I call the initialize method . And this should be only called once. Tried looking in other Pages,…
Himanshu
  • 65
  • 1
  • 5
5
votes
3 answers

Django - legacy db and problems with 'id' field

I'm integrating a MySQL database from a php app into a new Django project. Inspectdb worked well, I just had to change a couple of fields to ForeignKeys and now all the reading and editing current data is working great. The problem is when I try to…
j_syk
  • 6,511
  • 2
  • 39
  • 56
5
votes
2 answers

Database Routing by URL parameter

I'm developing on a Django Project with several Databases. In an App I need to switch the database connectivity from a Development-Database to Test-DB or Production-DB, based on a request from the user. (DB Architecture is set and not changeable!) I…
5
votes
0 answers

Django 2.0 - How to deal with testing on only one database when we have several?

First of all, I'm new to asking question here, so bear with me if I don't do it perfectly :) Here goes... I am setting up a Django2.0 API that is going to deal with statistics. It has its own 'default' database to write stuff obviously, but I am…
5
votes
3 answers

How to create model instances from command line (terminal)

I thought this would have been a previously asked question, so maybe I'm not phrasing it right. I tried: manage.py python3.6 dbshell and then: obj= Person.objects.create('Justin') but this did not work. Thanks for any help.
justin
  • 553
  • 1
  • 7
  • 18
5
votes
3 answers

Calling foreign key object several times in Django without several DB requests

Let’s say that I have a class Child linked, through a FK, to another class Parent. Now let’s say I have a block of code doing something like this in a template {{ child.parent.name }} {{ child.parent.age}} {{…
Y2H
  • 2,419
  • 1
  • 19
  • 37
5
votes
2 answers

Django Mass Update/Insert Performance

I'm receiving financial data for approximately 5000 instruments every 5 seconds, and need to update the respective entries in the database. The model looks as follows: class Market(models.Model): market = models.CharField(max_length=200) …
ceds
  • 2,097
  • 5
  • 32
  • 50
5
votes
3 answers

Django @transaction.atomic() to prevent creating objects in concurrency

I have a ticket model, and its ticket serialiazer. The ticket model has a bought and a booked_at field. And also a unique_together attribute for show and seat. class Ticket(models.Model): show = models.ForeignKey(Show, on_delete=models.CASCADE) …
Aamu
  • 3,431
  • 7
  • 39
  • 61
5
votes
2 answers

Detect field change using post_save instead of pre_save signal

I need to do some actions when one field has changed. Since this action needs to work with already saved object, I can't use pre_save signal like this: @receiver(pre_save, sender=reservation_models.Reservation) def generate_possible_pairs(sender,…
Milano
  • 18,048
  • 37
  • 153
  • 353
5
votes
2 answers

Django setting TIME_ZONE in DATABASES has no effect with 'date' lookup

UPDATE April 8th, 2019 This is a known bug for django<=2.2, fixed as of this PR ================================= (We assume the mysql backends) I can set TIME_ZONE several times in settings.py, one for the global django app, and one for each…