django-database

How to make Django work with unsupported MySQL drivers such as gevent-mysql or Concurrence's MySQL driver?

拈花ヽ惹草 提交于 2020-01-09 12:36:22
问题 I'm interested in running Django on an async framework like Concurrence or gevent. Both frameworks come with its own async MySQL driver. Problem is Django only officially supports MySQLdb. What do I need to do to make Django work with the MySQL drivers that come with gevent or Concurrence? Is there a step-by-step guide somewhere that I can follow? Is this a major undertaking? Thanks. 回答1: three cheers for @traviscline's suggestion to go with pymysql. his suggestion was based on this post from

Routing and middleware for multiple databases in Django

老子叫甜甜 提交于 2020-01-04 06:09:46
问题 I have a problem correctly setting my middleware and routers to support multiple databases, one for each language (I decided to keep them separate). I tried to use this solution, but for now I didn't get much use of it. In my settings.py databases and middleware are defined as follows: DATABASES = { 'default': {}, 'ru': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'db_ru.sqlite3', }, 'en': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'db_en.sqlite3', } } DATABASE_ROUTERS = ['me

Routing and middleware for multiple databases in Django

☆樱花仙子☆ 提交于 2020-01-04 06:09:12
问题 I have a problem correctly setting my middleware and routers to support multiple databases, one for each language (I decided to keep them separate). I tried to use this solution, but for now I didn't get much use of it. In my settings.py databases and middleware are defined as follows: DATABASES = { 'default': {}, 'ru': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'db_ru.sqlite3', }, 'en': { 'ENGINE': 'django.db.backends.sqlite3', 'NAME': 'db_en.sqlite3', } } DATABASE_ROUTERS = ['me

Specifying Readonly access for Django.db connection object

妖精的绣舞 提交于 2020-01-03 17:23:47
问题 I have a series of integration-level tests that are being run as a management command in my Django project. These tests are verifying the integrity of a large amount of weather data ingested from external sources into my database. Because I have such a large amount of data, I really have to test against my production database for the tests to be meaningful. What I'm trying to figure out is how I can define a read-only database connection that is specific to that command or connection object.

Specifying Readonly access for Django.db connection object

橙三吉。 提交于 2020-01-03 17:23:21
问题 I have a series of integration-level tests that are being run as a management command in my Django project. These tests are verifying the integrity of a large amount of weather data ingested from external sources into my database. Because I have such a large amount of data, I really have to test against my production database for the tests to be meaningful. What I'm trying to figure out is how I can define a read-only database connection that is specific to that command or connection object.

Django Table with Million of rows

陌路散爱 提交于 2019-12-31 22:25:23
问题 I have a project with 2 applications ( books and reader ). Books application has a table with 4 milions of rows with this fields: book_title = models.CharField(max_length=40) book_description = models.CharField(max_length=400) To avoid to query the database with 4 milions of rows, I am thinking to divide it by subject ( 20 models with 20 tables with 200.000 rows ( book_horror, book_drammatic, ecc ). In "reader" application, I am thinking to insert this fields: reader_name = models.CharField

DRF IntegrityError: NOT NULL constraint failed: user_id

对着背影说爱祢 提交于 2019-12-25 00:36:45
问题 I can't figure out how to pass user object to the following serializer: class ReviewSerializer(serializers.ModelSerializer): user = UserSerializer(read_only=True) class Meta: model = Review fields = ('pk', 'title', 'user', 'movie', 'timestamp', 'review_text',) I have this viewset: class ReviewsViewSet(viewsets.ModelViewSet): queryset = Review.objects.all() serializer_class = ReviewSerializer and this model: class Review(models.Model): title = models.CharField(max_length=255) user = models

Sharing (mysql) database between apps Django with Database routers

☆樱花仙子☆ 提交于 2019-12-24 01:44:11
问题 I've created a django project and then two apps, app1 and app2. I want that both apps share a mysql database('nameofDB' to mysql, 'mydb' to django). I added the database to DATABASES in settings.py and for each app I created a dbrouter file, and added each router to DATABASE_ROUTERS. Also in settings.py added each app to INSTALLED_APPS. My problem is when I try to make python manage.py syncdb --database=mydb Because it doesn't sync both apps(only app1). It says: Creating tables ... Creating

django.db.utils.IntegrityError: (1062, “Duplicate entry '22-add_' for key 'content_type_id'”)

不问归期 提交于 2019-12-23 03:22:17
问题 I am using django multiple DB router concepts, having multiple sites with different db's. Base database user will login with all other sub sites. When i try syncdb in base site its worked properly(at any time), but trying syncdb with other sites works first time only, if we try next time on-wards it throws integiry error like below django.db.utils.IntegrityError: (1062, "Duplicate entry '22-add_somesame' for key 'content_type_id'") Once i removed multiple DB router settings in that project

Issues with feeding data into database when using for loop

怎甘沉沦 提交于 2019-12-21 21:32:37
问题 In my template I have used for loop for some fields <div class="register_div"> <p>Title:</p> <p>{{ form.title }}</p> </div> <div class="register_div"> <p>Upload Images :</p> <p>{{ form.image }}</p> </div> {% for item in product %} <div class="register_div"> <p>{{ item.Name }} <input type="text" name="custom[{{item.id}}]"/></p> </div> {% endfor %} <div class="register_div"> <p>Price:</p> <p>{{ form.price }}</p> </div> As code shows there is one field which using for loops if that field has