0

Is there any way to use the SQL Command CREATE VIEW in Django? If I Try To use regular syntax, or use

from django.db import connection
... 
with connection.cursor()
...

I get the Error:

Incorrect syntax near the keyword 'VIEW'.

3
  • What error did you get Commented Jan 29, 2022 at 9:40
  • Edited the Error Commented Jan 29, 2022 at 9:46
  • Post the SQL query that you are using. Also check if using a migration is suitable for your case stackoverflow.com/questions/66853070/… Commented Jan 29, 2022 at 9:48

1 Answer 1

2

as usual creating view in sql is look like below:

create view in SQL named Test:

from django.db import connection
...
...
def createView(self):
    with connection.cursor() as cursor:
        cursor.execute('DROP VIEW IF EXISTS dbo.Test')
        cursor.execute("CREATE VIEW Test AS \
                        SELECT column1, column2, column3, ...\
                        FROM some_table_name \
                        WHERE condition")

Check your syntax with mine, if still has problem please place your whole code here.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.