PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, April 18, 2022

[FIXED] how to create laravel migration for postgresql array data type

 April 18, 2022     laravel, laravel-migrations, postgresql     No comments   

Issue

I have the following laravel migration up method

public function up()
{
    Schema::create('users', function (Blueprint $table) {
        $table->id();
        $table->string('name');
        $table->string('email')->unique();
        $table->string('mobile')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        // $table->string('sports');
        $table->date('dob');
        $table->string('height');
        $table->rememberToken();
        $table->timestamps();
    });

    DB::statement('ALTER TABLE users ADD COLUMN sports TYPE text[] AFTER password');
}

when I run migration it will show SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "text" LINE 1: ALTER TABLE users ADD COLUMN sports TYPE text[] AFTER passwo... ^ (SQL: ALTER TABLE users ADD COLUMN sports TYPE text[] AFTER password). I don't know what's a problem there?


Solution

please try your Sql statement like this:

 DB::statement('alter table users alter sports drop default');
    DB::statement('alter table users alter sports type text[] using array[sports]');
    DB::statement("alter table users alter sports set default '{}'");


Answered By - OMR
Answer Checked By - Terry (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing