Database Migrations

Let's create a Knowledgebase Application

In this video lesson we will work on our database migrations. We will use them to build our database and migrated all of our tables.

Video Information

Welcome back to Laracademy everyone, it's Mickey again and in this lesson we are going to create the database migration for our Knowledge Base. Let's start off by taking a look at our schema

As you can see we are leaving the user table alone and we are creating thee tables. So let's load up the terminal and create the migration files.

php artisan make:migration create_category_table --create=categories

php artisan make:migration create_articles_table --create=articles

php artisan make:migration cerate_article_category_table --create=article_ category

Now we can open them up in database/migrations. Let's start off with our categories migration.

// categories
Schema::create('categories', function (Blueprint $table) {
  $table->increments('id');
  $table->string('name');
  $table->boolean('active')->default(true);
  $table->timestamps();
});

// articles
Schema::create('articles', function (Blueprint $table) {
  $table->increments('id');
  $table->string('title');
  $table->mediumText('markdown');
  $table->boolean('active')->default(true);
  $table->timestamps();
});

// article_category
Schema::create('article_category', function (Blueprint $table) {
  $table->increments('id');
  $table->integer('category_id')->unsigned();
  $table->integer('article_id')->unsigned();
});

Now that we have our database migrations let's ensure that our .env file is ready. We want to ensure that our database variable are correct.

Finally let's load our terminal back up and run:

php artisan migrate

Our database has been migrated and our tables are ready for us to use. Our next lesson will be creating the database models and relationships between the tables. Thanks for watching.

Do you have a question? Go ahead and ask it below.

Please login to ask your question