0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【MySQL(MariaDB)】実運用を想定したECサイト用のER図をDBに反映する

Posted at

前回の記事のテーブルをもとにしてMySQL(MariaDB)で反映していきましょう。

テーブルの作成は下記の順番で作成してください。

users
↓
adminusers
↓
adminuser_photos
↓
products
↓
orders
↓
order_items
↓
product_photos

すると下記のようにテーブルが作成されます。

image.png

トラブルシューティング

テーブル範囲されないエラー

MySQLにDB「jakartaeerestful」を作成し、order_items、products、product_photosテーブルを作成しようとしたが下記のエラーが出た。

SQLエラー(1005) Cannot create table jakartaeerestful.order_items
(errorno: 150 Foreign key constraint is incorrectly formed)

MySQLで非常によく出る典型的な外部キーエラー です。

エラー内容の意味

SQLエラー(1005)
Foreign key constraint is incorrectly formed

👉 外部キー定義が正しく作れない という意味
👉 order_items product_id/order_id外部キー が原因

✅ 原因:products テーブルが存在しない or 先に作られていない
👉 参照先テーブルは必ず「先に」作成されている必要があります

products
↓
orders
↓
order_items
↓
product_photos

サイト

【MySQL(MariaDB)】実運用を想定したECサイト用のER図設計

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?