I have a table called “Order Detail” that does not contain PK
I want it to show all the products in the order. but before doing that I wanted to perform a Print and I got the following error:
Models
class Pedido(models.Model): # Order
cod_pedido = models.AutoField(primary_key=True)
user= models.CharField(max_length=50)
class Meta:
managed = False
db_table = 'pedido'
class Detalle_pedido(models.Model): # Order detail
pedido_id = models.ForeignKey(Pedido, db_column="pedido_id", on_delete=models.CASCADE)
cod_art = models.ForeignKey(Stock, db_column="cod_art", on_delete=models.CASCADE)
cant_pedida = models.IntegerField()
class Meta:
managed = False
db_table = 'detalle_pedido'
OperationalError at /stock/verpedido/1/
(1054, “Unknown column ‘detalle_pedido.id’ in ‘field list’”)
Request Method: | GET |
---|---|
Request URL: | http://127.0.0.1:8000/stock/verpedido/1/ |
Django Version: | 4.2.5 |
Exception Type: | OperationalError |
Exception Value: | (1054, “Unknown column ‘detalle_pedido.id’ in ‘field list’”) |
Exception Location: | C:\Users\marti\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\MySQLdb\connections.py, line 255, in query |
Raised during: | stock.views.verPedido |
Python Executable: | C:\Users\marti\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\python.exe |
Python Version: | 3.9.13 |
Python Path: | [‘C:\Users\marti\OneDrive\Documentos\GitHub\testDjango\InsumoTestCasa’, 'C:\Program ’ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\python39.zip’, 'C:\Program ’ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\DLLs’, 'C:\Program ’ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib’, ‘C:\Users\marti\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0’, ‘C:\Users\marti\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages’, 'C:\Program ’ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0’, 'C:\Program ’ ‘Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.3568.0_x64__qbz5n2kfra8p0\lib\site-packages’] |
Server time: | Sun, 05 Nov 2023 23:25:47 +0000 |
How can I solve this problem or how can I use my table without the need to add an auto-incremental id.