You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#When i run a migration and create all tables for the models below.
I run into the error when creating invoice and trying to add invoiceitem to that invoice
Error:"(1146, "Table 'defaultdb.invoices_invoice_items' doesn't exist")"
from enum import Enum
from tortoise.models import Model
from tortoise import fields
#When i run a migration and create all tables for the models below.
I run into the error when creating invoice and trying to add invoiceitem to that invoice
Error:"(1146, "Table 'defaultdb.invoices_invoice_items' doesn't exist")"
from enum import Enum
from tortoise.models import Model
from tortoise import fields
# --- Invoice Item Model ---
class InvoiceItemModel(Model):
id = fields.UUIDField(pk=True)
item = fields.ForeignKeyField("models.ItemModel", related_name="invoice_items", on_delete=fields.CASCADE)
totalAmount = fields.DecimalField(max_digits=10, decimal_places=2)
quantity = fields.IntField()
numInstalment = fields.IntField()
paymentPlanPrice = fields.DecimalField(max_digits=10, decimal_places=2)
description = fields.TextField(null=True)
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
**# --- Invoice Status Model --- **
class InvoiceStatus(Enum):
New = "New"
Active = "Active"
Overdue = "Overdue"
Completed = "Completed"
Cancelled = "Cancelled"
Refund = "Refund"
# --- Invoice Model ---
class InvoiceModel(Model):
id = fields.UUIDField(pk=True)
invoiceNumber = fields.CharField(max_length=255, unique=True)
customer = fields.ForeignKeyField("models.CustomerModel", related_name="invoices", on_delete=fields.CASCADE)
items = fields.ManyToManyField("models.InvoiceItemModel", related_name="invoices", through="invoices_invoice_items")
vat = fields.DecimalField(max_digits=10, decimal_places=2)
covidTax = fields.DecimalField(max_digits=10, decimal_places=2)
totalAmount = fields.DecimalField(max_digits=10, decimal_places=2)
subTotal = fields.DecimalField(max_digits=10, decimal_places=2)
status = fields.CharEnumField(InvoiceStatus, default=InvoiceStatus.New)
paymentType = fields.CharField(max_length=255)
paymentPlanAmount = fields.DecimalField(max_digits=10, decimal_places=2)
note = fields.TextField(null=True)
overDueDate = fields.DatetimeField(null=True)
setDate = fields.DatetimeField(null=True)
created_at = fields.DatetimeField(auto_now_add=True)
updated_at = fields.DatetimeField(auto_now=True)
after manually creating "invoices_invoice_items" using the sql schema below
example:
"CREATE TABLE IF NOT EXISTS
invoices_invoice_items
(invoice_id
CHAR(36) NOT NULL,invoice_item_id
CHAR(36) NOT NULL,CONSTRAINT
fk_invoices_invoice_items_invoice_id
FOREIGN KEY (invoice_id
) REFERENCESinvoices
(id
) ON DELETE CASCADE,CONSTRAINT
fk_invoices_invoice_items_invoice_item_id
FOREIGN KEY (invoice_item_id
) REFERENCESinvoice_items
(id
) ON DELETE CASCADE,PRIMARY KEY (
invoice_id
,invoice_item_id
)) CHARACTER SET utf8mb4 COMMENT='Join table for InvoiceModel and InvoiceItemModel';"
Now when i try to create an invoice after building all the tables. The new error i get is "(1054, "Unknown column 'invoices_id' in 'where clause'")"
The text was updated successfully, but these errors were encountered: