Laravel迁移:“未找到"类 [英] Laravel migrations: Class "not found"
问题描述
我正在将Laravel准系统项目部署到Microsoft Azure,但是每当我尝试执行php artisan migrate
时,我都会收到错误消息:
I am deploying a Laravel barebone project to Microsoft Azure, but whenever I try to execute php artisan migrate
I get the error:
[2015-06-13 14:34:05]生产.错误:D:\ home \ site \ vendor \中出现异常"Symfony \ Component \ Debug \ Exception \ FatalErrorException",消息为"Class" laravel \ framework \ src \ Illuminate \ Database \ Migrations \ Migrator.php:328
[2015-06-13 14:34:05] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Class '' not found' in D:\home\site\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:328
堆栈跟踪:
#0 {main}
可能是什么问题?非常感谢
What could be the problem? Thank you very much
迁移类
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateUsersTable extends Migration {
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function(Blueprint $table)
{
$table->bigIncrements('id');
$table->string('name', 50);
$table->string('surname', 50);
$table->bigInteger('telephone');
$table->string('email', 50)->unique();
$table->string('username', 50)->unique();
$table->string('password', 50);
$table->boolean('active')->default(FALSE);
$table->string('email_confirmation_code', 6);
$table->enum('notify', ['y', 'n'])->default('y');
$table->rememberToken();
$table->timestamps();
$table->index('username');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('users');
}
}
推荐答案
对于PSR-4自动加载程序用户(composer.json):
将迁移文件夹保留在classmap
数组内,并且不要将其包含在autoload
头下的psr-4对象内.由于迁移的主类Migrator不支持命名空间.例如;
Keep the migrations folder inside classmap
array and do not include it inside psr-4 object under autoload
head. As migrations' main class Migrator doesn't support namespacing. For example;
"autoload": {
"classmap": [
"app/database/migrations"
],
"psr-4": {
"Acme\\controllers\\": "app/controllers"
}
}
然后运行:
php artisan clear-compiled
php artisan optimize:clear
composer dump-autoload
php artisan optimize
- 第一个清除所有编译的自动加载文件.
- 第二次清除Laravel缓存(可选)
- 第三种方法为命名空间类构建自动加载器.
- Fourth可以优化Laravel应用的各个部分,并为非命名空间的类构建自动加载器.
- First one clears all compiled autoload files.
- Second clears Laravel caches (optional)
- Third builds the autoloader for namespaced classes.
- Fourth optimizes various parts of your Laravel app and builds the autoloader for non-namespaced classes.
从现在开始,您无需再做一次,任何新的迁移都将正常工作.
From this time on wards, you will not have to do this again and any new migrations will work correctly.
这篇关于Laravel迁移:“未找到"类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!