前言
最近断断续续开始 laravel 入门学习,想整个简单的通讯录系统,设立了两个表,一个 branches ,一个 contacts。在创建 migration 文件的时候,没有考虑仔细,先把 contacts 表建立了,contacts 表有个外键连接到 branches 的 id,结果执行 migrate 命令的时候,出现以下错误:
[Illuminate/Database/QueryException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint (SQL: alter table `contacts` add constraint `contac ts_branch_id_foreign` foreign key (`branch_id`) references `branches` (`id`) on delete cascade) [PDOException] SQLSTATE[HY000]: General error: 1215 Cannot add foreign key constraint
初步怀疑是表创建先后不规范造成,于是,手动修改 branches 的 migration 文件名称上的日期,再执行
php artisan migrate:reset
出现如下错误:
[ErrorException] include(/Users/Ade/www/laravel_phonebook5.2): failed to open stream: Operation now in progress
failed to open stream 错误解决
光看错误提示不是很理解,我们查看 laravel 的 log 文件
more storage/logs/laravel.log
找到出现 ERROR 的那段话:
[2016-09-29 18:05:35] local.ERROR: exception 'ErrorException' with message 'include(/Users/Ade/www/laravel_phonebook5.2): failed to open stream: Operation now in progress' in /Users/Ade/www/laravel_phonebook5.2/vendor/composer/ClassLoader.php:412 Stack trace: #0 /Users/Ade/www/laravel_phonebook5.2/vendor/composer/ClassLoader.php(412): Illuminate/Foundation/Bootstrap/HandleExceptions->handleError(2, 'include(/Users/...', '/Users/Ade/www/...', 412, Array) #1 /Users/Ade/www/laravel_phonebook5.2/vendor/composer/ClassLoader.php(412): Composer/Autoload/includeFile() #2 /Users/Ade/www/laravel_phonebook5.2/vendor/composer/ClassLoader.php(301): Composer/Autoload/includeFile('/Users/Ade/www/...') #3 [internal function]: Composer/Autoload/ClassLoader->loadClass('CreateBranchesT...') #4 /Users/Ade/www/laravel_phonebook5.2/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(335): spl_autoload_call('CreateBranchesT...') #5 /Users/Ade/www/laravel_phonebook5.2/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(227): Illuminate/Database/Migrations/Migrator->resolve('2016_09_12_1728...') #6 /Users/Ade/www/laravel_phonebook5.2/vendor/laravel/framework/src/Illuminate/Database/Migrations/Migrator.php(206): Illuminate/Database/Migrations/Migrator->runDown(Object(stdClass), false)
错误出现在 ClassLoader.php 文件的 412 行
查看改行代码,发现是一个调用文件的语句:
而这个文件,在 log 文件中已经指出,即
新闻热点
疑难解答