我创建一个新的网络应用,在那里我有3个表:users
,teams
和project
:laravel鼓捣当插入到数据库
这里是team
和project
迁移结构:
Schema::create('teams', function (Blueprint $table) {
$table->increments('id');
$table->string('team_image', 15);
$table->string('team_name', 50);
$table->string('team_description');
$table->timestamps();
});
Schema::create('project', function (Blueprint $table) {
$table->increments('id');
$table->integer('members')->unsigned();
$table->foreign('members')->references('id')->on('teams');
$table->string('name');
$table->string('description');
$table->string('lead');
$table->timestamps();
});
这里有Team
和Project
型号:
class Team extends Model
{
protected $table = 'teams';
public function projects()
{
return $this->hasMany('App\Project');
}
}
class Project extends Model
{
protected $table = 'project';
protected $fillable = ['name', 'description'];
public function teams()
{
return $this->belongsTo('App\Team');
}
}
In修补程序我运行这个:
$team = factory('App\Team')->create();
而且我得到了人口稠密的数据库的福克博士珍宝,这就好了。但是,当我试图把这个项目:
$team->projects()->create(['name'=>'project 1', 'description'=>'bla bla']);
我得到这个:
照亮\数据库\ QueryException与消息“SQLSTATE [42S22]: 列未找到:1054未知列 'TEAM_ID'在 '字段列表'(SQL: 插入到
project
(name
,description
,team_id
,updated_at
,created_at
)值(项目1,血乳酸血乳酸,2,2015年12月20日0时06分29秒, 2015-12- 20 00:06:29))'
而且team_id
代替members
,在前面几个迁移使用,但我已经reseted迁移和更新迁移文件并重新运行迁移和DB是罚款,创建members
列。
当我将members
替换为team_id
时,修补程序工作并将名称插入到project
表中。
任何线索?
感谢波格丹,我需要更多的阅读,所以这帮助了我很多,并解决了这个问题。 TNX – pinarella