dongmi4734 2018-11-13 08:12
浏览 45

即使遵循迁移过程,我也无法从laravel向表中添加新列?

I am following all the steps for adding new column votes to the user table from laravel, still there isn't in the database? Please tell me where is my mistake? Firstly php artisan make:migration add_votes_to_users_table --table=users

public function up()
{
    Schema::table('users', function (Blueprint $table) {
         $table->integer('votes');
    });
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('users', function (Blueprint $table) {
        $table->dropColumn('votes');
    });
}
php artisan migrate

enter image description here

Error from cmd- In Connection.php line 647:

SQLSTATE[42S01] And In Connection.php line 449:

SQLSTATE[42S01]: Base table or view already exists: 1050 Table 'users' already exists

  • 写回答

4条回答 默认 最新

  • douzhuang1900 2018-11-13 08:36
    关注

    I am suspecting that the reason you are getting this errors can come from 2 sides.

    1) you created users table yourself without run any migration

    2) a migration was interrupted.

    If the above does not work try:

    php artisan migrate:reset
    

    to rollback all your changes or if you want to move back 1 step at a time you can try:

    php artisan migrate:rollback --step=1
    

    Last if you are sure you can start over and you are ok with that you can run:

    php artisan migrate:fresh
    

    This will drop all the tables (check the database just to be sure as well and drop yourself any remaining even though i don't think anything will be left, never happened to me) and then run

    php artisan migrate 
    

    all over again

    评论

报告相同问题?

悬赏问题

  • ¥15 求.net core 几款免费的pdf编辑器
  • ¥20 SQL server表计算问题
  • ¥15 C# P/Invoke的效率问题
  • ¥20 thinkphp适配人大金仓问题
  • ¥20 Oracle替换.dbf文件后无法连接,如何解决?(相关搜索:数据库|死循环)
  • ¥15 数据库数据成问号了,前台查询正常,数据库查询是?号
  • ¥15 算法使用了tf-idf,用手肘图确定k值确定不了,第四轮廓系数又太小才有0.006088746097507285,如何解决?(相关搜索:数据处理)
  • ¥15 彩灯控制电路,会的加我QQ1482956179
  • ¥200 相机拍直接转存到电脑上 立拍立穿无线局域网传
  • ¥15 (关键词-电路设计)