前提・実現したいこと
今回初めてlaravelアプリをMAMP環境からHerokuにデプロイします。
その途中で、heroku run "php artisan migrate"のコマンド後に下記のエラーに遭遇してから詰まっています。
mamp環境下でのmigrateは正常です。
外部キー制約と関係あるのでしょうか。
エラーを解消してデプロイするにはどうしたらいいでしょうか。
発生している問題・エラーメッセージ
Method Illuminate\Database\Schema\Blueprint::references does not exist.
該当のソースコード
このファイルをmigrate中にエラーが起こります。atabase/migrations/2019_08_20_062213_add_user_id_to_shops_table.php <?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class AddUserIdToShopsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::table('shops', function (Blueprint $table) { $table->integer('user_id')->unsigned(); $table ->foreign('user_id') ->references('id') ->on('users') ->onDelete('cascade'); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::table('shops', function (Blueprint $table) { $table->dropForeign('shops_user_id_foreign'); }); } }
database/migrations/2019_08_14_205903_create_shops_table.php
<?php use Illuminate\Support\Facades\Schema; use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration; class CreateShopsTable extends Migration { /** * Run the migrations. * * @return void */ public function up() { Schema::create('shops', function (Blueprint $table) { $table->increments('id'); $table->string('name'); $table->string('address'); $table->integer('category_id')->unsigned(); $table->integer('subcategory_id')->unsigned(); $table->timestamps(); }); } /** * Reverse the migrations. * * @return void */ public function down() { Schema::dropIfExists('shops'); } }
app/User.php
<?php namespace App; use App\Notifications\ResetPasswordNotification; use Illuminate\Notifications\Notifiable; use Illuminate\Contracts\Auth\MustVerifyEmail; use Illuminate\Foundation\Auth\User as Authenticatable; class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast to native types. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', ]; public function sendPasswordResetNotification($token) { $this->notify(new ResetPasswordNotification($token)); } public function shops() { return $this->hasMany(\App\Shop::class,'user_id', 'id'); } }
app/Shop.php
<?php namespace App; use Illuminate\Database\Eloquent\Model; class Shop extends Model { protected $fillable = [ 'name', 'address', 'category_id', 'subcategory_id', 'user_id', 'image', ]; public function category() { return $this->belongsTo('App\Category'); } public function subcategory() { return $this->belongsTo('App\SubCategory'); } public function user() { return $this->belongsTo('App\User'); } }
補足情報(FW/ツールのバージョンなど)
PHP 7.1.23
Laravel Framework 5.7.28
回答1件
あなたの回答
tips
プレビュー