php


Updating Existing Column Attributes - Laravel 5 Migration


I have
a existing column called cpe_mac. I created it via migration like this :
$table->string('cpe_mac')->default(NULL)->nullable();
I want
I want to add this ->unique() to that column, without having to drop it and re-add.
I've tried
$table->string('cpe_mac')->unique();
Migration File
<?php
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class AlterCaptivePortalTable212017 extends Migration
{
/**
* Run the migrations.
*
* #return void
*/
public function up()
{
Schema::table('captive_portals', function (Blueprint $table) {
$table->string('cpe_mac')->unique();
});
}
/**
* Reverse the migrations.
*
* #return void
*/
public function down()
{
Schema::table('captive_portals', function (Blueprint $table) {
$table->string('cpe_mac')->default(NULL)->nullable();
});
}
}
I kept
getting
SQLSTATE[42701]: Duplicate column: 7 ERROR: column "cpe_mac" of relation "captive_portals" already exists
Is there to achive this without having to drop my existing column ?
(I have a lot client data that can't be deleted !)
How would one go about and implement this ?
I'm opening to any suggestions at this moment.
Any hints / suggestions / helps on this be will be much appreciated !
Schema::table('users', function (Blueprint $table) {
$table->string('cpe_mac')->unique()->change();
});
https://laravel.com/docs/5.0/schema#changing-columns
You need to use change() method:
Schema::table('captive_portals', function (Blueprint $table) {
$table->string('cpe_mac')->unique()->change();
});
Alternatively, you may create the index after defining the column. For example:
$table->unique('email');
https://laravel.com/docs/5.4/migrations#indexes
If the column is already defined you can use:
$table->unique('cpe_mac');

Related Links

displaying array difference in php when arrays coming from mysql_fetch_array
Unable to edit record from a table PDO PHP
.htaccess to have index.php and assets inside a public folder
Edit Mikrotik User Profile With PHP API
How do I deploy php code in GAE once I've connected it to Bitbucket?
PHP runs, echo command doesn't render anything
Change query parameter using .htacess & redirect
Bootstrap form submission not able to use $_POST data
Unknown php file path in a login form
how to go new line in cell in table in phpword?
Filtering Search Query with AngularJS and PHP
Enacting a POST request to URL in Symfony using CURL
Password validation with Regex
How to show SQL error in PHP custom mysqli function?
HTML Email not sending properly When using CRON
Daily update on PHP logic

Categories

HOME
generics
jms
applescript
tabs
malware
gallery
dependencies
flurry
drag-and-drop
impala
clone
static-analysis
scheduler
erd
ex
temperature
mixpanel
scala-ide
dashdb
sharedpreferences
pymongo
quantitative-finance
restier
animated-gif
mod-wsgi
web-push
ipa
ruby-daemons
php-5.3
winsock
phpstorm-2016.1
steam-web-api
microsoft-certifications
mongoengine
markov-chains
gnu-classpath
adminer
creation
spring-rabbitmq
java-stream
polyml
express-session
stackpanel
ms-solver-foundation
djcelery
uivisualeffectview
telephonymanager
selenide
jacoco-maven-plugin
icepdf
httphandler
transparency
nuclio
jenkins-slave
adblock
.net-micro-framework
supertest
phppgadmin
aurelia-fetch-client
winmerge
test-data
glimpse
mpmovieplayercontroller
thread-exceptions
callouts
jtag
bbc-micro
mnesia
gdl
stack-smash
arbre
nette
apple
hmisc
wlanapi
componentart
kefir.js
phpredis
unidata
tree-structure
azure-xplat-cli
rfc5545
signed
sunos
adwords-apiv201402
inequality
jquery-mobile-flipswitch
xcode6.3.1
category-theory
incognito-mode
windows-taskbar
typesafe-stack
boinc
notifyjs
form-for
axacropdf
contextswitchdeadlock
towers-of-hanoi
zend-pdf
jzmq
trialware
servercontrol
glassfish-esb
representation
space-partitioning
azure-acs
mongrel2
cleartype
oracle-pro-c
fuzzy-comparison
twitter-feed
objectinstantiation
comment-conventions
bindable-linq

Resources

Encrypt Message