1. <tfoot id='BISVp'></tfoot>

      <small id='BISVp'></small><noframes id='BISVp'>

        <legend id='BISVp'><style id='BISVp'><dir id='BISVp'><q id='BISVp'></q></dir></style></legend>

      1. <i id='BISVp'><tr id='BISVp'><dt id='BISVp'><q id='BISVp'><span id='BISVp'><b id='BISVp'><form id='BISVp'><ins id='BISVp'></ins><ul id='BISVp'></ul><sub id='BISVp'></sub></form><legend id='BISVp'></legend><bdo id='BISVp'><pre id='BISVp'><center id='BISVp'></center></pre></bdo></b><th id='BISVp'></th></span></q></dt></tr></i><div id='BISVp'><tfoot id='BISVp'></tfoot><dl id='BISVp'><fieldset id='BISVp'></fieldset></dl></div>
          <bdo id='BISVp'></bdo><ul id='BISVp'></ul>
      2. 未找到 Laravel 4 迁移基表

        Laravel 4 migrate base table not found(未找到 Laravel 4 迁移基表)
          <bdo id='eWCpp'></bdo><ul id='eWCpp'></ul>
            <i id='eWCpp'><tr id='eWCpp'><dt id='eWCpp'><q id='eWCpp'><span id='eWCpp'><b id='eWCpp'><form id='eWCpp'><ins id='eWCpp'></ins><ul id='eWCpp'></ul><sub id='eWCpp'></sub></form><legend id='eWCpp'></legend><bdo id='eWCpp'><pre id='eWCpp'><center id='eWCpp'></center></pre></bdo></b><th id='eWCpp'></th></span></q></dt></tr></i><div id='eWCpp'><tfoot id='eWCpp'></tfoot><dl id='eWCpp'><fieldset id='eWCpp'></fieldset></dl></div>

            <tfoot id='eWCpp'></tfoot>

                <legend id='eWCpp'><style id='eWCpp'><dir id='eWCpp'><q id='eWCpp'></q></dir></style></legend>

                  <small id='eWCpp'></small><noframes id='eWCpp'>

                    <tbody id='eWCpp'></tbody>
                  本文介绍了未找到 Laravel 4 迁移基表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试制作以下教程:https://medium.com/on-coding/e8d93c9ce0e2

                  I'm trying to make following tutorial: https://medium.com/on-coding/e8d93c9ce0e2

                  当谈到运行时:

                  php artisan migrate
                  

                  我收到以下错误:

                  [Exception]                                                                        
                  SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel.user' doesn't   
                  exist (SQL: alter table `user` add `id` int unsigned not null auto_increment prim  
                  ary key, add `username` varchar(255) null, add `password` varchar(255) null, add   
                  `email` varchar(255) null, add `created_at` datetime null, add `updated_at` datet  
                  ime null) (Bindings: array (                                                       
                  ))
                  

                  数据库连接正常,迁移表创建成功.如您在错误消息中所见,数据库名称已更改.

                  Database connection is working, the migrations table was created successfully. Database name was changed as you can see in the error message.

                  对我来说很奇怪的是,它试图改变表——它不存在——而不是创建它.

                  Whats quite strange to me, is that it tries to alter the table - which doesn't exists - and not to create it.

                  这是我的其他文件,例如 UserModel、Seeder、Miggation 和 DB Config.

                  Here are my other files, like UserModel, Seeder, Migtation and DB Config.

                  创建用户表:

                  <?php
                  
                  use IlluminateDatabaseSchemaBlueprint;
                  use IlluminateDatabaseMigrationsMigration;
                  
                  class CreateUserTable extends Migration {
                  
                  /**
                   * Run the migrations.
                   *
                   * @return void
                   */
                  public function up()
                  {
                      Schema::table('user', function(Blueprint $table)
                      {
                  
                          $table->increments("id");
                  
                          $table
                              ->string("username")
                              ->nullable()
                              ->default(null);
                          $table
                              ->string("password")
                              ->nullable()
                              ->default(null);
                          $table
                              ->string("email")
                              ->nullable()
                              ->default(null);
                          $table
                              ->dateTime("created_at")
                              ->nullable()
                              ->default(null);
                          $table
                              ->dateTime("updated_at")
                              ->nullable()
                              ->default(null);
                  
                      });
                  }
                  
                  /**
                   * Reverse the migrations.
                   *
                   * @return void
                   */
                  public function down()
                  {
                      Schema::table('user', function(Blueprint $table)
                      {
                          Schema::dropIfExists("user");
                      });
                  }
                  
                  }
                  

                  用户模型:

                  use IlluminateAuthUserInterface;
                  use IlluminateAuthRemindersRemindableInterface;
                  
                  class User extends Eloquent implements UserInterface, RemindableInterface {
                  
                  /**
                   * The database table used by the model.
                   *
                   * @var string
                   */
                  protected $table = 'user';
                  
                  /**
                   * The attributes excluded from the model's JSON form.
                   *
                   * @var array
                   */
                  protected $hidden = array('password');
                  
                  /**
                   * Get the unique identifier for the user.
                   *
                   * @return mixed
                   */
                  public function getAuthIdentifier()
                  {
                      return $this->getKey();
                  }
                  
                  /**
                   * Get the password for the user.
                   *
                   * @return string
                   */
                  public function getAuthPassword()
                  {
                      return $this->password;
                  }
                  
                  /**
                   * Get the e-mail address where password reminders are sent.
                   *
                   * @return string
                   */
                  public function getReminderEmail()
                  {
                      return $this->email;
                  }
                  
                  }
                  

                  用户种子:

                  class UserSeeder extends DatabaseSeeder
                  {
                  public function run()
                  {
                      $users = [
                          [
                              "username" => "ihkawiss",
                              "password" => Hash::make("123456"),
                              "email"    => "ihkawiss@domain.com"
                          ]
                      ];
                  
                      foreach ($users as $user)
                      {
                          User::create($user);
                      }
                  }
                  }
                  

                  数据库播种机:

                  class DatabaseSeeder extends Seeder {
                  
                  /**
                   * Run the database seeds.
                   *
                   * @return void
                   */
                  public function run()
                  {
                      Eloquent::unguard();
                  
                      $this->call('UserSeeder');
                  }
                  
                  }
                  

                  数据库配置:

                  return array(
                  
                  /*
                  |--------------------------------------------------------------------------
                  | PDO Fetch Style
                  |--------------------------------------------------------------------------
                  |
                  | By default, database results will be returned as instances of the PHP
                  | stdClass object; however, you may desire to retrieve records in an
                  | array format for simplicity. Here you can tweak the fetch style.
                  |
                  */
                  
                  'fetch' => PDO::FETCH_CLASS,
                  
                  /*
                  |--------------------------------------------------------------------------
                  | Default Database Connection Name
                  |--------------------------------------------------------------------------
                  |
                  | Here you may specify which of the database connections below you wish
                  | to use as your default connection for all database work. Of course
                  | you may use many connections at once using the Database library.
                  |
                  */
                  
                  'default' => 'mysql',
                  
                  /*
                  |--------------------------------------------------------------------------
                  | Database Connections
                  |--------------------------------------------------------------------------
                  |
                  | Here are each of the database connections setup for your application.
                  | Of course, examples of configuring each database platform that is
                  | supported by Laravel is shown below to make development simple.
                  |
                  |
                  | All database work in Laravel is done through the PHP PDO facilities
                  | so make sure you have the driver for your particular database of
                  | choice installed on your machine before you begin development.
                  |
                  */
                  
                  'connections' => array(
                  
                      'sqlite' => array(
                          'driver'   => 'sqlite',
                          'database' => __DIR__.'/../database/production.sqlite',
                          'prefix'   => '',
                      ),
                  
                      'mysql' => array(
                          'driver'    => 'mysql',
                          'host'      => 'localhost',
                          'database'  => 'laravel',
                          'username'  => 'root',
                          'password'  => '',
                          'charset'   => 'utf8',
                          'collation' => 'utf8_unicode_ci',
                          'prefix'    => '',
                      ),
                  
                      'pgsql' => array(
                          'driver'   => 'pgsql',
                          'host'     => 'localhost',
                          'database' => 'database',
                          'username' => 'root',
                          'password' => '',
                          'charset'  => 'utf8',
                          'prefix'   => '',
                          'schema'   => 'public',
                      ),
                  
                      'sqlsrv' => array(
                          'driver'   => 'sqlsrv',
                          'host'     => 'localhost',
                          'database' => 'database',
                          'username' => 'root',
                          'password' => '',
                          'prefix'   => '',
                      ),
                  
                  ),
                  
                  /*
                  |--------------------------------------------------------------------------
                  | Migration Repository Table
                  |--------------------------------------------------------------------------
                  |
                  | This table keeps track of all the migrations that have already run for
                  | your application. Using this information, we can determine which of
                  | the migrations on disk have not actually be run in the databases.
                  |
                  */
                  
                  'migrations' => 'migrations',
                  
                  /*
                  |--------------------------------------------------------------------------
                  | Redis Databases
                  |--------------------------------------------------------------------------
                  |
                  | Redis is an open source, fast, and advanced key-value store that also
                  | provides a richer set of commands than a typical key-value systems
                  | such as APC or Memcached. Laravel makes it easy to dig right in.
                  |
                  */
                  
                  'redis' => array(
                  
                      'cluster' => true,
                  
                      'default' => array(
                          'host'     => '127.0.0.1',
                          'port'     => 6379,
                          'database' => 0,
                      ),
                  
                  ),
                  
                  );
                  

                  希望有人可以在这里给我一个提示.

                  Hope somebody can give me a hint here.

                  最好的问候 ihkawiss

                  Best regards ihkawiss

                  推荐答案

                  在你的 CreateUserTable 迁移文件中,你必须使用 而不是 Schema::tableSchema::create.

                  In your CreateUserTable migration file, instead of Schema::table you have to use Schema::create.

                  Schema::table 用于更改现有表,Schema::create 用于创建新表.

                  The Schema::table is used to alter an existing table and the Schema::create is used to create new table.

                  查看文档:

                  • http://laravel.com/docs/schema#creating-and-dropping-tables
                  • http://laravel.com/docs/schema#adding-columns

                  所以您的用户迁移将是:

                  So your user migration will be:

                  <?php
                  
                  use IlluminateDatabaseSchemaBlueprint;
                  use IlluminateDatabaseMigrationsMigration;
                  
                  class CreateUserTable extends Migration {
                  
                      /**
                       * Run the migrations.
                       *
                       * @return void
                       */
                      public function up()
                      {
                          Schema::create('user', function(Blueprint $table) {
                          {
                  
                              $table->increments("id",true);
                              $table->string("username")->nullable()->default(null);
                              $table->string("password")->nullable()->default(null);
                              $table->string("email")->nullable()->default(null);
                              $table->timestamps();
                  
                          });
                      }
                  
                      /**
                       * Reverse the migrations.
                       *
                       * @return void
                       */
                      public function down()
                      {
                          Schema::dropIfExists("user");
                      }
                  
                  }
                  

                  这篇关于未找到 Laravel 4 迁移基表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Laravel 4 - Connect to other database(Laravel 4 - 连接到其他数据库)
                  Call external API function from controller, LARAVEL 4(从控制器调用外部 API 函数,LARAVEL 4)
                  Empty string instead of null values Eloquent(空字符串而不是空值 Eloquent)
                  quot;laravel.logquot; could not be opened: failed to open stream(“laravel.log无法打开:无法打开流)
                  Displaying the Error Messages in Laravel after being Redirected from controller(从控制器重定向后在 Laravel 中显示错误消息)
                  Laravel Creating Dynamic Routes to controllers from Mysql database(Laravel 从 Mysql 数据库创建到控制器的动态路由)

                  <small id='is9cG'></small><noframes id='is9cG'>

                  • <tfoot id='is9cG'></tfoot>
                      • <bdo id='is9cG'></bdo><ul id='is9cG'></ul>
                        <legend id='is9cG'><style id='is9cG'><dir id='is9cG'><q id='is9cG'></q></dir></style></legend>

                      • <i id='is9cG'><tr id='is9cG'><dt id='is9cG'><q id='is9cG'><span id='is9cG'><b id='is9cG'><form id='is9cG'><ins id='is9cG'></ins><ul id='is9cG'></ul><sub id='is9cG'></sub></form><legend id='is9cG'></legend><bdo id='is9cG'><pre id='is9cG'><center id='is9cG'></center></pre></bdo></b><th id='is9cG'></th></span></q></dt></tr></i><div id='is9cG'><tfoot id='is9cG'></tfoot><dl id='is9cG'><fieldset id='is9cG'></fieldset></dl></div>

                              <tbody id='is9cG'></tbody>