1

I am working with laravel 5.6 and PostgreSQL 9.6 and I am trying to change the datatype of a column date from date to integer using a migration below.

<?php

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

class ChangeBidDateTypeInAucBiddingsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('auc_biddings', function (Blueprint $table) {
            //
            $table->integer('bid_date')->change();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::table('auc_biddings', function (Blueprint $table) {
            //
            $table->date('bid_date')->change();
        });
    }
}

But every time I run the migration I get the following error

In PDOStatement.php line 107:

SQLSTATE[42804]: Datatype mismatch: 7 ERROR: column "bid_date" cannot be cast automatically to t ype integer HINT: You might need to specify "USING bid_date::integer".

Kindly assist on how I can achieve changing a column datatype using migration. Thanks

Below are some of the codes from composer.json

"require": {
        "php": ">=7.0.0",
        "doctrine/dbal": "^2.6",
        "fideloper/proxy": "~3.3",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "predis/predis": "~1.0",
        "tymon/jwt-auth": "dev-develop"
    },
4
  • have you ran composer require doctrine/dbal ? Commented Mar 14, 2018 at 14:06
  • Yes I have, I have edited the question to show my composer.json file Commented Mar 15, 2018 at 10:10
  • Well, there are ways around it, like creating a new column and pass all data to there and delete the old, or use DB::raw and use direct alter tables to achieve that. but using what you're trying i'm afraid i can't help much more Commented Mar 15, 2018 at 10:22
  • The solution in this and similar cases appears to be to code the SQL yourself. See also the answers to these other SO questions: stackoverflow.com/questions/22060398/… and stackoverflow.com/questions/63005845/… Commented Mar 14, 2023 at 19:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.