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

Thursday, April 14, 2022

[FIXED] How can I update the data type of a column inside a table in Laravel?

 April 14, 2022     database-migration, laravel, migration, php     No comments   

Issue

I am trying to update the data type of my column due to it requiring encryption. I created a new migration to do so and have tried this:

public function up()
{
    Schema::table('users', function(Blueprint $table) {
        $table->dropColumn(['team', 'service_number']);
        $table->string('team', 188);
        $table->string('service_number', 188);
    });
}

However, I get this error:

SQLSTATE[42S21]: Column already exists: 1060 Duplicate column name 'team' (SQL: alter table `users` add `team` varchar(1024) not null, add `service_number` varchar(1024) not null)

How can I update the data type of my columns in my table?


Solution

I think you need to do this (though that won't drop the columns):

    $table->string('team', 188)->change();
    $table->string('service_number', 188)->change();


Answered By - Rok Sprogar
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • 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