Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php migrate:refresh命令laravel的意外行为_Php_Mysql_Laravel - Fatal编程技术网

Php migrate:refresh命令laravel的意外行为

Php migrate:refresh命令laravel的意外行为,php,mysql,laravel,Php,Mysql,Laravel,我想在我的mysql数据库中更新一个名为“annonce”的表,我使用的是带有php 5.6.31的wamp server,我通过更改迁移文件向现有表中添加了一些列,具体来说是up函数,下面是更改前的函数: public function up() { Schema::create('annonce', function (Blueprint $table) { $table->engine = 'InnoDB'; $table-

我想在我的mysql数据库中更新一个名为“annonce”的表,我使用的是带有php 5.6.31的wamp server,我通过更改迁移文件向现有表中添加了一些列,具体来说是up函数,下面是更改前的函数:

       public function up()
   {
    Schema::create('annonce', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('ID_annonce');
        $table->integer('ID_sous_categorie')->unsigned();
        $table->integer('ID_compte')->unsigned();
        $table->String('Titre');
        $table->enum('Type',['Offre','Demande']);
        $table->String('Description');
        $table->date('DatePublication');
        $table->integer('Longitude');
        $table->integer('Latitude');
        $table->foreign('ID_sous_categorie')->references('ID_sous_categorie')->on('sous_categorie')->onDelete('no action')->onUpdate('cascade');
        $table->foreign('ID_compte')->references('ID_categorie')->on('categorie')->onDelete('cascade')->onUpdate('cascade');
    });
}
我向表中添加了7个新列:

      public function up()
{
    Schema::create('annonce', function (Blueprint $table) {
        $table->engine = 'InnoDB';
        $table->increments('ID_annonce');
        $table->integer('ID_sous_categorie')->unsigned();
        $table->integer('ID_compte')->unsigned();
        $table->String('Titre');
        $table->enum('Type',['Offre','Demande']);
        $table->String('Description');
        $table->date('DatePublication');
        $table->integer('Longitude');
        $table->integer('Latitude');
        $table->String('Nom');
        $table->String('Prenom');
        $table->String('Telephone');
        $table->String('Email');
        $table->String('Photo1');
        $table->String('Photo2');
        $table->String('Photo3');
        $table->foreign('ID_sous_categorie')->references('ID_sous_categorie')->on('sous_categorie')->onDelete('no action')->onUpdate('cascade');
        $table->foreign('ID_compte')->references('ID_categorie')->on('categorie')->onDelete('cascade')->onUpdate('cascade');
    });
}

然而,当我运行命令:php artisan migrate:refresh时,它成功地执行了,但是当我使用phpmyadmin检查我的数据库时,看起来数据已经被删除(这是预期的),但是“annonce”的表结构仍然是一样的,我很困惑,非常感谢您的帮助。

当Laravel创建一个表时,您应该使用Schema::create,它将删除整个数据

如果表已经存在,请考虑使用:


这将添加新列

我认为您需要使用Schema::table而不是Schema::created您是否有
Schema::dropIfExists('annonce')
down()
迁移的一部分中?成功了!!谢谢你的澄清,这甚至都不在我的雷达上。
Schema::table('users', function (Blueprint $table) {
    $table->string('email');
});