New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PostgreSQL - unique error #17263
Comments
Related to #12135 |
And eventually I stumbled upon
|
The proper way of doing this right now is
|
Yes, but I would like to know, what is the "proper" way to solve the problem. On one side we can't split the whole task to subqueries. On other side we can't do the task by single query. |
I'm not sure what is the best way of fixing this. PostgreSQL behaves here differently from the other DBMS, more atomically. Let's take classic example:
For MySQL if we would do migration like:
it means that column lost its default value. But with
we've got CHAR column with default value according to the first idea. As for PostgreSQL - with
we switched column to CHAR but we still got the default. For the following to work
we would have to change the output of And with the previous statement for it to work like in MySQL we would have to add hidden |
I've tried to work on this but I'm stuck on how to handle some cases. Let's take this example
We could do it with 2 statements:
or... throw exception?
On the other hand if we choose first option to make it compatible with other DMBS should we handle
like this:
The second statement almost for sure triggers error when there is no constraint with that name. And currently we are not checking previous column definition to detect if this DROP is needed. What do you think @samdark @cebe @SilverFire ? |
Throwing exception isn't a good idea since migrations become non-interoperable i.e. product can not use them for being installable on MySQL, PostgreSQL etc. at the same time. Multiple statements are OK. We can add another statement for checking if constraint exists for that field before dropping it. |
What steps will reproduce the problem?
In migration script:
$this->alterColumn({{%table}}, ‘id’, $this->string(50)->unique());
What is the expected result?
The specified column in table changed to specified type and condition.
What do you get instead?
Additional info
The syntax in psql should be in format:
ALTER TABLE the_table ADD CONSTRAINT constraint_name UNIQUE (thecolumn);
Running with PostgreSQL version 9.5.16
The text was updated successfully, but these errors were encountered: