Welcome Guest, Not a member yet? Register   Sign In
How can I remove a unique constraint on a field when performing a down migration?
#1

Copy-pasted from https://stackoverflow.com/questions/6503...-migration, feel free to answer the question there too to win a few points.

I have to add a unique constraint to a field after the table was created. I therefore set up a migration file with this in the up() method:
Code:
$fields = [
    'slug' => [
        'type' => 'varchar',
        'constraint' => 255,
        'unique' => true
    ]
];
$this->forge->modifyColumn('pages', $fields);
And in down():
Code:
$fields = [
    'slug' => [
        'type' => 'varchar',
        'constraint' => 255,
        'unique' => false
    ]
];
$this->forge->modifyColumn('pages', $fields);
This doesn't work.

When calling
Code:
php spark migrate:rollback
, the migration is correctly un-applied ("migrations" table is modified) but the fields stay unique.
What should I put in down() instead?
Reply


Messages In This Thread
How can I remove a unique constraint on a field when performing a down migration? - by SteeveDroz - 12-02-2020, 02:48 AM



Theme © iAndrew 2016 - Forum software by © MyBB