I am using below code in Schema Builder to create table.
Schema::create('tblCategory', function (Blueprint $table) { $table->increments('CategoryID'); $table->string('Category', 40); $table->unique('Category', 'tblCategory_UK_Category'); $table->timestamps(); });
Here is the problem is, if I have to create the new table, all old scripts runs and show error that table already exists.
is there any way to create table if not exists using Schema builder ?
Change your 'table_name' value. If you get one row output, it means the table exists.
PHP empty() Function The empty() function checks whether a variable is empty or not. This function returns false if the variable exists and is not empty, otherwise it returns true. The following values evaluates to empty: 0.
It means the middle_name field can also store null values: as in inserting a value is not required.
How to rollback a specific migration in laravel ? Step 1 : Open database and check migrations table. Step 2 : Change batch number to last number. Step 3 : Run artisan rollback command.
Try this
if (!Schema::hasTable('tblCategory')) { Schema::create('tblCategory', function($table){ $table->engine = 'InnoDB'; $table->increments('CategoryID'); $table->string('Category', 40); $table->unique('Category', 'tblCategory_UK_Category'); $table->timestamps(); } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With