Issue
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'.
Solution
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.
Answered By - Mahyar Majidi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.