zoukankan      html  css  js  c++  java
  • LARAVEL框架及数据迁移

    一、数据迁移三步骤

    配置数据库连接

    首先在 .env 中配置数据库连接信息,如php连接数据库,需要先选择在那个数据库,然后再进行操作

    创建数据库迁移文件

    输入如下命令

    php artisan make:migration create_post_table

      创建文件成功后开始编辑数据内容。
    public function up()
        {
            Schema::create('post', function (Blueprint $table) {
                $table->increments('id');
                $table->string("title")->default('');
                $table->string("content")->default('');
                $table->timestamps();
            });
        }

    编辑好数据内容,开始执行 迁移文件命令

     php artisan migrate

    二、创建文件成功后,开始增删改查

    代码修改好后,重新运行数据库迁移

    提示没有迁移任何内容

    解决方案是在数据库中删除 post 表,并将 migrations 表中的对应数据删除,然后重新运行数据库迁移即可

    再创建新的表

    修改数据库迁移文件

    class PostTypeTable extends Migration
    {
        /**
         * Run the migrations.
         *
         * @return void
         */
        public function up()
        {
            Schema::create('post_type', function (Blueprint $table) {
                $table->increments('id');
                $table->string("title")->default('');
                $table->timestamps();
            });
        }
    
        /**
         * Reverse the migrations.
         *
         * @return void
         */
        public function down()
        {
            Schema::dropIfExists('post_type');
        }
    }

    配置路由

    // 展示待编辑数据
    Route::get('/posts/{post}/edite','AppHttPControllersPostController@edite');
  • 相关阅读:
    git clone 很慢提速方法
    在Windows上安装pytorch
    关于一些知名深度学习模型的转换
    【转】安装caffe2的参考
    Nasty Hacks
    寻梦
    Fibonacci Again
    统计元音
    首字母变大写
    查找最大元素
  • 原文地址:https://www.cnblogs.com/Rawan/p/12008330.html
Copyright © 2011-2022 走看看