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'.

Amitai
  • 21
  • 5

1 Answers1

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.