I create the models file with inspectdb, but it gives an error when I want to show it in Admin panel:
(1054, "Unknown column 'order_product.id' in 'field list'")
In my searches, I realized I had to add a primary key to each of the models, but nothing happened when I did that.
Here is my code:
# models.py
class OrderProduct(models.Model):
order = models.ForeignKey('Orders', models.DO_NOTHING)
product = models.ForeignKey('Products', models.DO_NOTHING)
attribute = models.ForeignKey(Attributes, models.DO_NOTHING, blank=True, null=True)
color = models.ForeignKey(Colors, models.DO_NOTHING, blank=True, null=True)
price = models.IntegerField(blank=True, null=True)
attribute_price_differ = models.IntegerField(blank=True, null=True)
attribute_price = models.IntegerField(blank=True, null=True)
number = models.IntegerField(blank=True, null=True)
class Meta:
managed = False
db_table = 'order_product'
class Orders(models.Model):
id = models.BigAutoField(primary_key=True)
user = models.ForeignKey('Users', models.DO_NOTHING)
price = models.IntegerField()
weight = models.IntegerField()
coupon = models.ForeignKey(Coupons, models.DO_NOTHING, blank=True, null=True)
status = models.IntegerField()
process_status = models.IntegerField()
code = models.CharField(max_length=255)
hash = models.CharField(max_length=255)
created_at = models.DateTimeField(blank=True, null=True)
updated_at = models.DateTimeField(blank=True, null=True)
class Meta:
managed = False
db_table = 'orders'
# admin.py
@admin.register(OrderProduct)
class PostAdmin(admin.ModelAdmin):
pass