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
4
votes
2 answers

What is the most efficient way to iterate django objects updating them?

So I have a queryset to update stories = Story.objects.filter(introtext="") for story in stories: #just set it to the first 'sentence' story.introtext = story.content[0:(story.content.find('.'))] + ".

" story.save() And the save()…
straykiwi
  • 538
  • 6
  • 23
4
votes
1 answer

multiple execute on a single connection.cursor in django. Is it safe?

I am opening a cursor with connection.cursor executing a bunch of deletes then closing the cursor. It works, but I am not sure if it has any side effect. Would appreciate any feedback. from django.db import connection c=connection.cursor() try: …
4
votes
4 answers

Generate a few models from existing database in Django

I know this exists django-admin.py inspectdb > models.py However, is there an easy way to limit it? Without manually deleting what I don't want. I'm connecting to a database that has over one hundred tables, but I only want models of about 4 or 5.…
colinjwebb
  • 4,362
  • 7
  • 31
  • 35
4
votes
1 answer

Which is faster: using django database order_by or list sort?

I have a Django model with score and quizzes_done. I want to calculate percentiles on both scores and quizzes_done. To do that, I need to create two sorted lists. For the first one, I do: s_recs = MyRecord.objects.all().order_by('score') score_list…
zaphod
  • 2,045
  • 1
  • 14
  • 18
3
votes
0 answers

installing mysql for python within virtual environment

I went through other similar questions, but none of the stuffs mentioned there, served my purpose. My OS is ubuntu 11.04, What i did was created a virtual environment first: virtualenv mysite once this was done, i installed django pip install…
user993563
  • 18,601
  • 10
  • 42
  • 55
3
votes
2 answers

Getting error - Cannot add or update a child row: a foreign key constraint fails for a legacy database in django

I recently ported from raw php to django and had to incorporate my legacy database into it. I used the inspectdb command to construct the models out of the database and everything was working fine. Recently I decided to add the functionality of…
Sachin
  • 3,672
  • 9
  • 55
  • 96
3
votes
1 answer

Django models: are there reasons to make searched field with db_index?

Supose there is table UserProfile: class UserProfile(models.Model): name = models.CharField(max_length=30, db_index=True) # db_index 1 email = models.EmailField(unique=True, db_index=True) # db_index 2 password =…
Vitalii Ponomar
  • 10,686
  • 20
  • 60
  • 88
3
votes
0 answers

Database queries to 'new-database' are not allowed in this test

I have added a new database in my django project. Now I have run into issues with my test cases. I am keep getting this error message for every single of my test cases: Database queries to 'new-database' are not allowed in this test I have searched…
3
votes
4 answers

Is there a way to update the database with the changes in my models?

Possible Duplicate: update django database to reflect changes in existing models I've used Django in the past and one of the frustrations I've had with it as an ORM tools is the inability to update an existing database with changes in the model.…
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411
3
votes
1 answer

Filtering down through multiple ForeignKey relations in django

I am trying to get down through multiple-foreign key relationship where each Hotel has many Rooms, each Room has many Rateplans, each Rateplan has many Prices. It resembles Christmas tree if you think about it: Hotel v Room v Rateplan v Prices How…
3
votes
1 answer

Why Does Django Query to Check Uniqueness?

tl;dr: Why does Django's uniqueness check on INSERT require a SELECT query, and can I permanently disable it? I'm working to highly optimize a Django app that is writing to a PSQL database. I have a uuid column which is a primary_key as part of my…
3
votes
2 answers

pandas to_sql in django: insert foreign key into DB

Is there a way to insert foreign keys when using pandas to_sql function? I am processing uploaded Consultations (n=40k) with pandas in django, before adding them to the database (postgres). I got this working row by row, but that takes 15 to 20…
3
votes
1 answer

Can Django's select_for_update deadlock when used on the same record twice?

I have some code that would be a lot simpler with nested calls to select_for_update(), but I'm afraid I'm setting myself up for a deadlock. Example: with transaction.atomic(): uu1 = UniUser.objects.select_for_update().get(pk=uupk) with…
mgalgs
  • 15,671
  • 11
  • 61
  • 74
3
votes
1 answer

Problem with running IBM DB2 connection in Django for Windows

I'm new to Django and am trying to connect two databases. One is a .sqlite3 DB and the other is a DB2 database. `DATABASES = { 'default': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': os.path.join(BASE_DIR,…
Eric Taurone
  • 137
  • 8
3
votes
2 answers

Django specify which database to use for module

In my Django project I have a couple of applications, one of them is email_lists and this application does a lot of data handling reading data from the Model Customers. In my production environment I have two databases: default and read-replica. I…
PepperoniPizza
  • 8,842
  • 9
  • 58
  • 100