相关疑难解决方法(0)

如何使用Eloquent删除表中的所有行?

我的猜测是使用以下语法:

MyModel::all()->delete();
Run Code Online (Sandbox Code Playgroud)

但那没用.我确信它非常简单,但我已经搜索了关于这个主题的文档而无法找到它!

laravel eloquent laravel-4

115
推荐指数
10
解决办法
14万
查看次数

Laravel 5.1迁移和种子无法截断外键约束中引用的表

我正在尝试运行迁移(见下文)并为数据库播种,但是当我运行时

php artisan migrate --seed
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

Migration table created successfully.
Migrated: 2015_06_17_100000_create_users_table
Migrated: 2015_06_17_200000_create_password_resets_table
Migrated: 2015_06_17_300000_create_vehicles_table

[Illuminate\Database\QueryException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table
referenced in a foreign key constraint (`app`.`vehicles`, CONSTRAINT `vehic
les_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `app`.`users` (`id`
)) (SQL: truncate `users`)

[PDOException]
SQLSTATE[42000]: Syntax error or access violation: 1701 Cannot truncate a table
referenced in a foreign key constraint (`app`.`vehicles`, CONSTRAINT `vehic
les_user_id_foreign` FOREIGN KEY (`user_id`) REFERENCES `app`.`users` (`id`
))
Run Code Online (Sandbox Code Playgroud)

我查看了这个错误应该是什么意思,并且还找到了遇到同样问题的其他人的 …

mysql laravel laravel-5 laravel-seeding laravel-migrations

19
推荐指数
5
解决办法
2万
查看次数