Django 3.2 + Python3.8
每次update表时希望把以前的记录清空并且id也从0开始计数
model 类大体如下 (方法从网上copy过来的)
class StockInfo(models.Model):
......
@classmethod
def truncate(cls):
with connection.cursor() as cursor:
cursor.execute('TRUNCATE TABLE "{0}"on_delete=models.CASCADE'.format(cls._meta.db_table))
从浏览器调用
http://127.0.0.1:8000/updatestockinfo/
def updatestockinfo(request):
StockInfo.truncate()
.......
总是报以下下错误。
ProgrammingError at /updatestockinfo/
(1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'"stocks_stockinfo"on_delete=models.CASCADE\' at line 1')
Request Method: GET
Request URL:
http://127.0.0.1:8000/updatestockinfo/Django Version: 3.2
Exception Type: ProgrammingError
Exception Value:
(1064, 'You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near \'"stocks_stockinfo"on_delete=models.CASCADE\' at line 1')
--
FROM 45.51.104.*