-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Django Test Error - relation does not exist #7
Comments
For current solution, from dbview.models import DbView
class ProductCategoriesCounterView(DbView):
class Meta:
managed = False
db_table = "product_categories_counter"
@classmethod
def get_view_str(cls):
return """
CREATE OR REPLACE VIEW product_categories_counter AS (SELECT
pc.id,
pc.name,
pc.slug,
(SELECT COUNT(1) FROM product_product_categories WHERE category_id=pc.id) AS total_product,
pc.parent_id as parent_id,
pc.created,
pc.updated,
pc.deleted,
pc.image,
pc.image_caption
FROM product_categories pc
LEFT JOIN product_categories pcx ON pcx.id=pc.parent_id
)"""
|
Looks like Meta.db_table is ignored for some reason. I'm not sure how to reproduce this though… |
Hi guys, i'm working with python 3.7.4, django 3.0.5, and django-database-view 0.3.0; with a Postgresql database. All works fine for me. When you work with a DB view you must provide some field as a primary_key=True inside your django model code, for example: field_x = models.UUIDField(primary_key=True); but you must ensure that your DB view (sql statement) does have this specific field (field_x). There's no need to make a relation field like OneToOneField, ForeignKey, etc (unless your DB view require this, and only when the DB view meets the condition that it only has a unique register for that relation id). By the other side, as @vinoalterra said, when you work with a DB view in Django, you must define the meta options AFTER YOU RUN MIGRATIONS (don't use this before you create your DB view) Where your db_view_name must be the same in the sql statement: CREATE VIEW db_view_name AS.... |
Can you please show your migration file and the output of running migrate?
Can you please re-run the test with verbosity increased ( |
Thanks for a great package.
I have problem while running Django Test after creating DB View using Django Migration.
Test Case:
3.8.6
(Mac OSX)Django==3.1.1
django-database-view==0.2.1
python manage.py migrate
without any problempython manage.py. test
with this errorAny help?
The text was updated successfully, but these errors were encountered: