django-database

database error no such table django

南楼画角 提交于 2019-12-21 21:24:56
问题 I have made a new app 'api' in the django project 'cc'. I have a remote database 'launchg' which I integrated it with Django using Legacies and used python manage.py inspectdb > models.py to generate a models.py file. Next replaced the generated models.py file with the models.py file in the api app. Whenever I try to fire a query into this Database database error:no such table For Eg :- WebQuery.objects.all() , it throws an error stating database error: no such table : web_query Here is my

Django - Runtime database switching

人盡茶涼 提交于 2019-12-18 21:19:44
问题 In my work we want to run a server with multiple databases. The databases switching should occur when you acces a url like http://myapp.webpage.com or http://other.webpage.com . We want to run only one server instance and at the moment of the HTTP request switch the database and return the corresponding response. We've been looking for a mantainable and 'Django-friendly' solution. In our investigation we have found possible ways to do this, but we have not enough information about. Option 1:

Simple Subquery with OuterRef

假装没事ソ 提交于 2019-12-18 10:24:29
问题 I am trying to make a very simple Subquery that uses OuterRef (not for practical purposes, just to get it working), but keep running into same error. posts/models.py from django.db import models class Tag(models.Model): name = models.CharField(max_length=120) def __str__(self): return self.name class Post(models.Model): title = models.CharField(max_length=120) tags = models.ManyToManyField(Tag) def __str__(self): return self.title manage.py shell code >>> from django.db.models import OuterRef

“Returning to that page might cause any action you took to be repeated” - Django

荒凉一梦 提交于 2019-12-17 23:51:07
问题 I have a form on my website, that creates an entry in database. So every time when I refresh a page I got this message first: The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue? Obviously I don't want have the same information more than once in my database. just in case: this is my code (I know there is a lot of crap that needs to be deleted): #views.py @login_required def subject

Django: dynamic database file

核能气质少年 提交于 2019-12-17 10:34:38
问题 In my Django project I have a dependency for a third party application that produces SQLite cache files in various directories with a known schema. I'd like to use Django models to access those databases, but obviously I cannot use a static DATABASES setup. How can I dynamically open a SQLite database on an arbitrary path? EDIT As Byron Ruth pointed out, the solution is to use the django.db.connections in conjunction with the using function in the QuerySet. 回答1: The django.db.connections is a

Django channels 2, accessing db in tests

▼魔方 西西 提交于 2019-12-14 01:43:40
问题 I recently updated my project to Django 2 and channels 2. Right now I am trying to rewrite my tests for chat app. I am facing a problem with tests that depend on django db mark from pytest-django. I tried to create objects in fixtures, setup methods, in test function itself, using async_to_sync on WebsocketCommunicator . However, none of those worked. If I create a user in a fixture and save it correctly gets an id. However, in my consumer Django does not see that User in the database. And

Django - sqlclear fails to delete database with AbstractUser foreign key constraints

大憨熊 提交于 2019-12-13 01:07:14
问题 I'm using Django 1.6 + MySQL. My model has a custom_user class that extends AbstractUser. class CustomUser(AbstractUser): dob = models.DateField() class Meta: db_table = 'custom_user' I want to delete the database with ./manage.py sqlclear | ./manage.py dbshell (as mentioned here) The output of sqlclear is BEGIN; DROP TABLE `design`; DROP TABLE `company`; ALTER TABLE `custom_user_user_permissions` DROP FOREIGN KEY `customuser_id_refs_id_da27cb33`; ALTER TABLE `custom_user_groups` DROP FOREIGN

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

偶尔善良 提交于 2019-12-12 10:48:31
问题 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 = motor_trend, name = 'Camaro 2010', category = cars, condition = 'Used', price = '28,547.00', production_year = '2010', color_interior = 'Black', color_exterior = 'Inferno Orange Metallic', reference = 'PRC17288', location_of_creation = 'Undisclosed',

Django routing to database based on model table

核能气质少年 提交于 2019-12-11 15:33:07
问题 I have a Django (1.6) project with two databases. I have one app with one model, and multiple tables. I want to use the database routers to set specific tables in the model to a specific database. All the documentation I have found seems to explain how to route a particular app to a particular database. 回答1: Looks like you could use a custom router and model attribute for this. YMMV: Haven't tested this. https://docs.djangoproject.com/en/dev/topics/db/multi-db/#using-routers class MyModel

Deploying Django app's local postgres database to heroku?

泄露秘密 提交于 2019-12-11 15:07:53
问题 I am unsuccesfully getting my django app deployed on heroku to use my local postgres db. My DATABASE settings are as follows: DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'mydb', 'USER': 'foo', 'PASSWORD': 'bar', 'HOST': 'localhost', 'PORT': '', } } Everything runs fine locally. Following the instructions from https://devcenter.heroku.com/articles/django, I add the following bit a code to the bottom of my settings file: import dj_database_url