1

Im working in laravel 5.3, i want to add column in existing table (i.e., course_chapters). so that i have created migration file by the command

 php artisan make:migration add_description_to_course_chapters_table --table=course_chapters

Migration file was created and i have added some code to add column in that table as below

<?php
   use Illuminate\Support\Facades\Schema;
   use Illuminate\Database\Schema\Blueprint;
   use Illuminate\Database\Migrations\Migration;
   class AddDescriptionToCourseChaptersTable extends Migration {
       public function up() {
           Schema::table('course_chapters', function (Blueprint $table) {
               $table->text('description')->after('title');
           });
       }
       public function down(){
           Schema::table('course_chapters', function (Blueprint $table) {
               $table->dropColumn('description');
           });
       }
   }

After i run command

php artisan migrate

the table was not created instead of that i got error

←[37;41m
   ←[39;49m
←[37;41m  [Illuminate\Database\QueryException]
   ←[39;49m
←[37;41m  SQLSTATE[42000]: Syntax error or access violation: 1064 You have  an error i  ←[39;49m
←[37;41m  n your SQL syntax; check the manual that corresponds to your MariaDB server  ←[39;49m
←[37;41m   version for the right syntax to use near ') default character set    utf 8 col  ←[39;49m
←[37;41m  late utf8_unicode_ci' at line 1 (SQL: create table     `course_chapters` () def  ←[39;49m
←[37;41m  ault character set utf8 collate utf8_unicode_ci)
   ←[39;49m
←[37;41m
   ←[39;49m

←[37;41m
   ←[39;49m
←[37;41m  [Doctrine\DBAL\Driver\PDOException]
   ←[39;49m
←[37;41m  SQLSTATE[42000]: Syntax error or access violation: 1064 You have   an error i  ←[39;49m
←[37;41m  n your SQL syntax; check the manual that corresponds to your   MariaDB server  ←[39;49m
←[37;41m   version for the right syntax to use near ') default character set   utf 8 col  ←[39;49m
←[37;41m  late utf8_unicode_ci' at line 1


←[37;41m
   ←[39;49m
←[37;41m  [PDOException]
   ←[39;49m
←[37;41m  SQLSTATE[42000]: Syntax error or access violation: 1064 You have   an error i  ←[39;49m
←[37;41m  n your SQL syntax; check the manual that corresponds to your     MariaDB server  ←[39;49m
←[37;41m   version for the right syntax to use near ') default character set    utf 8 col  ←[39;49m
←[37;41m  late utf8_unicode_ci' at line 1
   ←[39;49m
←[37;41m
   ←[39;49m

Any answer?

My existing table migration file is

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CourseChapters extends Migration
{
    /**
    * Run the migrations.
    *
    * @return void
    */
   public function up()
   {
       Schema::create('course_chapters', function (Blueprint $table) {
           $table->increments('id');
           $table->integer('course_id');
           $table->integer('chapter_id');
           $table->string('title', 80);
           $table->string('source');
           $table->string('source_type');
           $table->string('max_attempts');
           $table->tinyInteger('status');
           $table->timestamps();
       });
    }

   /**
    * Reverse the migrations.
    *
    * @return void
    */
    public function down()
    {
        Schema::drop('course_chapters');
    }
 }
VinoCoder
  • 1,133
  • 5
  • 22
  • 45

1 Answers1

0

You are doing it well.

To modify/add column in existing database you must install doctrine/dbal, as you already have. But if you look at ->after() method, you will see that it's only working in MySQL database. Please look at this section in Laravel 5.3 Documentation

I think your problem is that you are using MariaDB.

zgabievi
  • 1,162
  • 6
  • 28