ycs77 / Laravel-shop

(目前沒有維護,僅支持 PHP 7.2) 用 Laravel 5.8 開發的簡易商城,前端介面採用 Bootstrap 4。
34 stars 11 forks source link

数据库迁移出错 #12

Closed noecs closed 4 years ago

noecs commented 5 years ago

我遇到的问题:我执行php artisan db:seed的时候,收到了以下错误: mysql version: 8.0 php version:7.3.1 os:macOS mojave 10.14.5

Illuminate\Database\QueryException  : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'attribute_id' in 'field list' (SQL: insert into `product_skus` (`price`, `stock`, `attr_items_index`, `product_id`, `attribute_id`, `updated_at`, `created_at`) values (660, 89127, , 31, 4, 2019-09-02 17:56:38, 2019-09-02 17:56:38))
ycs77 commented 5 years ago

已修復,可以再試試看!

noecs commented 5 years ago

似乎在迁移订单表的时候又出现了一些错误:

ErrorException  : Trying to get property of non-object

  at /Users/noecs/Project/Laravel-shop/database/factories/OrderItemFactory.php:14
    10|     $sku = $product->skus()->inRandomOrder()->first();
    11| 
    12|     return [
    13|         'amount'         => random_int(1, 5), // 购买数量随机 1 - 5 份
  > 14|         'price'          => $sku->price,
    15|         'rating'         => null,
    16|         'review'         => null,
    17|         'reviewed_at'    => null,
    18|         'product_id'     => $product->id,
noecs commented 5 years ago

我学习到了很多

ycs77 commented 5 years ago

嗯......你可以試試看將資料庫重新遷移&注入資料

php artisan migrate:fresh --seed

看看還會不會有問題

ycs77 commented 5 years ago

我也學到了不少啊...... Laravel admin 擴展實在不少的坑,原本想用官方提供的欄位就可以完成 SKU,但就是有很多 Bug,最後決定用 Vue 才勉強做出來 :relieved:。