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');
  • 相关阅读:
    Uploadify404无效链接
    java开发SSM框架的搭建(SpringMVC+Spring+MyBatis)
    PHP文件处理--操作文件
    机器学习01-kNN邻近算法
    多校 hdu
    iOS中OC给Category加入属性
    Wampserver 2.5 多网站配置方法
    c语言编写经验逐步积累4
    UVA 529 Addition Chains(迭代搜索)
    机器学习简史brief history of machine learning
  • 原文地址:https://www.cnblogs.com/Rawan/p/12008330.html
Copyright © 2011-2022 走看看