2015-09-16 5 views
0

Когда я пытаюсь перенести таблицы я создал я получаю эту ошибкуНе удается перенести таблицу с помощью Laravel 4

PHP Fatal error: Class 'Users' not found in /var/www/html/laravel/vendor/laravel/ 
framework/src/Illuminate/Database/Migrations/Migrator.php on line 301 
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException", 
"message":"Class 'Users' not found","file":"\/var\/www\/html\/laravel\/vendor 
\/laravel\/framework\/src\/Illuminate\/Database\/Migrations\/Migrator.php", 
"line":301}} 

Вот мой код:

Пользователи таблица:

<?php 

//Users Table 
use Illuminate\Database\Migrations\Migration; 
use Illuminate\Database\Schema\Blueprint; 

class CreateUsersTable extends Migration { 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('users', function(Blueprint $table) { 
      $table->increments('id'); 
      $table->string('username'); 
      $table->string('email'); 
      $table->string('password'); 
      $table->timestamps(); 
     }); 
    } 


    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down(){ 
    } 

} 

Сообщения таблице:

<?php 

use Illuminate\Database\Migrations\Migration; 
use Illuminate\Database\Schema\Blueprint; 

class CreatePostsTable extends Migration { 

    /** 
    * Run the migrations. 
    * 
    * @return void 
    */ 
    public function up() 
    { 
     Schema::create('posts', function(Blueprint $table) { 
      $table->increments('id'); 
      $table->string('title'); 
      $table->text('body'); 
      $table->string('m_keyword'); 
      $table->string('m_disc'); 
      $table->string('slug'); 
      $table->integer('user_id'); 
      $table->timestamps(); 
     }); 
    } 


    /** 
    * Reverse the migrations. 
    * 
    * @return void 
    */ 
    public function down() 
    { 
    } 

} 

http://laravel.io/bin/zj31n

ответ

0

Если вы получите вышеуказанную ошибку во время выполнения миграции, запустите следующую команду

composer dump-autoload 

Для получения дополнительной информации, http://laravel.com/docs/master/migrations#running-migrations

0

Может быть то, что пошло не так, что вы не звонили

php artisan migrate:rollback 

перед тем

php artisan migrate 

Попробуйте удалить таблицы и попытаться выполнить миграцию снова.

И еще одно. В столбце «user_id» в таблице «сообщений» должен быть подключен к таблице пользователей, как это:

Schema::table('posts', function(Blueprint $table) { 
    $table->foreign('user_id')->references('id')->on('users'); 
}); 

, и я назвал бы создать столбец таблицы, как это:

$table->unsignedInteger('user_id'); 

или

$table->integer('user_id')->unsigned(); 

 Смежные вопросы

  • Нет связанных вопросов^_^