Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/251.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 使用Laravel';s从单个配置文件迁移到管理db架构_Php_Laravel_Laravel 5_Migration_Database Schema - Fatal编程技术网

Php 使用Laravel';s从单个配置文件迁移到管理db架构

Php 使用Laravel';s从单个配置文件迁移到管理db架构,php,laravel,laravel-5,migration,database-schema,Php,Laravel,Laravel 5,Migration,Database Schema,我想使用Laravel的迁移来管理我的数据库。但是我需要一个配置文件来存储模式。大概是这样的: { user: { "id":"increments", "name":"string", "timestamps":"timestamps()" } } 当我再次将此文件更改为下面的文本时

我想使用Laravel的迁移来管理我的数据库。但是我需要一个配置文件来存储模式。大概是这样的:

        {
           user: {
                    "id":"increments",
                    "name":"string",
                    "timestamps":"timestamps()"
                 }
        }
当我再次将此文件更改为下面的文本时

        {
           user: {
                    "id":"increments",
                    "name":"string",
                    "password":"string",
                    "timestamps":"timestamps()"
                 }
        }
我希望能够运行命令并更改数据库,而不会丢失任何数据或创建其他配置文件

我可以使用laravel migrations实现这一点吗?或者如果您知道任何其他解决方案可以帮助我,并且我可以在laravel上使用该解决方案,而不会丢失任何laravel的数据库管理工具,请发表评论。
谢谢。

php artisan make:migration将\u密码\u添加到\u user
(您确定表名为user而不是users吗?)

在您的新迁移中

public function up()
{
    Schema::table('user', function($table) {
        $table->string('password');
    });
}
别忘了回滚

public function down()
{
    Schema::table('user', function($table) {
        $table->dropColumn('password');
    });
}
如果您有型号User,则该表应为users。。否则请确保有
protected$table='user'

--table和--create选项还可用于指示表的名称以及迁移是否将创建新表。这些选项只是用指定的表预填充生成的迁移存根文件:

php artisan make:迁移创建用户表--create=users


php artisan make:migration add_voces_to_users_table--table=users

php artisan make:migration add_password_to_user
(您确定该表名为user而非users吗?)

在您的新迁移中

public function up()
{
    Schema::table('user', function($table) {
        $table->string('password');
    });
}
别忘了回滚

public function down()
{
    Schema::table('user', function($table) {
        $table->dropColumn('password');
    });
}
如果您有型号User,则该表应为users。。否则请确保有
protected$table='user'

--table和--create选项还可用于指示表的名称以及迁移是否将创建新表。这些选项只是用指定的表预填充生成的迁移存根文件:

php artisan make:迁移创建用户表--create=users


php artisan make:migration将投票添加到用户表——表=用户

不幸的是,迁移不是这样工作的。它们是完全线性的,以前的迁移永远不会知道将来的迁移。这也会阻止迁移系统跟踪更改(变更等),因此与迁移设计范式背道而驰。@Ohgoddy是的,我知道。这就是为什么我说我可能需要使用Phinx或更好的解决方案来完成我想做的事情。不幸的是,迁移不是这样工作的。它们是完全线性的,以前的迁移永远不会知道将来的迁移。这也会阻止迁移系统跟踪更改(变更等),因此与迁移设计范式背道而驰。@Ohgoddy是的,我知道。这就是为什么我说我可能需要使用Phinx或更好的解决方案来完成我想做的事情。谢谢,但我认为你不理解我的问题:)这并不能回答问题。谢谢,但我认为你不理解我的问题:)这并不能回答问题。