Einfügen oder Aktualisieren in der Tabelle "Produkte" verstoßen gegen den Fehler aus dem Fremdschlüssel (Postgresql SpriJava

Java-Forum
Anonymous
 Einfügen oder Aktualisieren in der Tabelle "Produkte" verstoßen gegen den Fehler aus dem Fremdschlüssel (Postgresql Spri

Post by Anonymous »

Ich habe eine API im Spring Start und habe mich entschlossen, eine Modellreihenfolge zu erstellen, aber ich habe einige Datenbankfehler gefunden und ich habe beschlossen, meinen PG -Administrator einzugeben und alle Tabellen zu löschen und von vorne zu starten. Wenn ich jetzt mein Modellprodukt anfordere, finde ich den Fehler: < /p>

Code: Select all

2023-03-27T15:00:48.189-03:00  WARN 31677 --- [nio-8011-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 0, SQLState: 23503
2023-03-27T15:00:48.190-03:00 ERROR 31677 --- [nio-8011-exec-6] o.h.engine.jdbc.spi.SqlExceptionHelper   : ERROR: insert or update on table "products" violates foreign key constraint "fkselc31gul05wygg2llkv0v3yb"
Detail: Key (product_id)=(9c2655d0-c5a4-45f1-ba97-8b5fe1a385d8) is not present in table "orders".
2023-03-27T15:00:48.231-03:00  INFO 31677 --- [nio-8011-exec-6] o.h.e.j.b.internal.AbstractBatchImpl     : HHH000010: On release of batch it still contained JDBC statements
< /code>
Ich habe bereits versucht, alle Tabellen zu entfernen.  Ich habe auch versucht, eine andere Datenbank zu erstellen und die alte zu löschen, aber ich erhalte immer noch denselben Fehler < /p>
ordermodel < /p>
package com.api.business_manager_api.Models;

import jakarta.persistence.*;

import java.util.List;
import java.util.UUID;

@Entity
@Table(name = "ORDERS")
public class OrderModel {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID order_id;
@ManyToOne
@JoinColumn(name = "customer_id")
private CustomerModel customer;
@OneToMany
@JoinColumn(name = "product_id")
private List products;
@Column(nullable = false, length = 80)
private Float totalAmount;

public UUID getOrder_id() {
return order_id;
}

public void setOrder_id(UUID order_id) {
this.order_id = order_id;
}

public CustomerModel getCustomer() {
return customer;
}

public void setCustomer(CustomerModel customer) {
this.customer = customer;
}

public List getProducts() {
return products;
}

public void setProducts(List  products) {
this.products = products;
}

public Float getTotalAmount() {
return totalAmount;
}

public void setTotalAmount(Float totalAmount) {
this.totalAmount = totalAmount;
}
}

< /code>
productModel < /p>
package com.api.business_manager_api.Models;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jakarta.persistence.*;

import java.util.UUID;

@Entity
@Table(name = "PRODUCTS")
public class ProductModel {
private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private UUID product_id;

@Column(nullable = false, length = 80)
private String product;
@Column(nullable = true, length = 200)
private String image_url;
@Column(nullable = true, length = 80)
private String brand;
@Column(nullable = true, length = 80)
private String description;
@Column(nullable = true, length = 80)
private Float price;

@Column(nullable = true, length = 80)
private Float extraPrice;

@Column(nullable = false, length = 80)
private Integer stock;
@JsonIgnore
@ManyToOne
@JoinColumn(name = "category_id")
private CategoryModel productCategory;

public UUID getProduct_id() {
return product_id;
}

public void setProduct_id(UUID product_id) {
this.product_id = product_id;
}

public String getProduct() {
return product;
}

public void setProduct(String product) {
this.product = product;
}

public String getImage_url() {
return image_url;
}

public void setImage_url(String image_url) {
this.image_url = image_url;
}

public String getBrand() {
return brand;
}

public void setBrand(String brand) {
this.brand = brand;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public Float getPrice() {
return price;
}

public void setPrice(Float price) {
this.price = price;
}

public Integer getStock() {
return stock;
}

public void setStock(Integer stock) {
this.stock = stock;
}

public CategoryModel getProductCategory() {
return productCategory;
}

public void setProductCategory(CategoryModel productCategory) {
this.productCategory = productCategory;
}

public Float getExtraPrice() {
return extraPrice;
}

public void setExtraPrice(Float extraPrice) {
this.extraPrice = extraPrice;
}
}

< /code>
Ich weiß nicht, was die Reaktion wäre, denn wie ihr sehen könnt, hängt mein Produkt nicht von irgendetwas ab, um zu erstellen < /p>
Update!{
"order_id": "982f2270-28fa-4dcf-ba24-89b2c9f18bb5",
"customer": {
"customer_id": "c33d4cf7-a931-4818-8d86-94b6c56b9426",
"name": "Antoni Ancelotti",
"description": "italian",
"cellphone": "21 8494944",
"email": "[email protected]",
"note": "ok"
},
"products": [
{
"product_id": "47b0a1ff-71e7-4b08-a243-9cf01ff55af7",
"product": null,
"image_url": null,
"brand": null,
"description": null,
"price": null,
"extraPrice": null,
"stock": null
},
{
"product_id": "47b0a1ff-71e7-4b08-a243-9cf01ff55af7",
"product": "Galaxy A13 128 GB Slim",
"image_url": "/products/images/e40989d2-66g8-4531-be26-00c124a8dfd6-SM-A136UZRAATT-8.webp",
"brand": null,
"description": "galaxy",
"price": 50.0,
"extraPrice": null,
"stock":  50
}
],
"totalAmount": 1800.0
}

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post