-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Alter column, set as NOT NULL and Set Default value, PostgreSQL. #12077
Comments
@akkicode do you mean that exactly same SQL executes well directly? |
@samdark Yes that's the exact SQL query that works in the database. With exact syntax in pgsql.
|
Just ran into this as well and can verify using the multiple ALTER COLUMN syntax fixes it: http://stackoverflow.com/a/16197615/684 |
@takobell thanks for confirming it. Would you like to make a pull request? |
@takobell thanks mate for the answer but this is again the static task. And this is solved personally with such static queries but this is not the solution i was looking for. |
@samdark хм... Глянул код и пока что единственным решением вижу в районе этого метода https://github.com/yiisoft/yii2/blob/master/framework/db/pgsql/QueryBuilder.php#L218-L227 строить запрос который будет менять тип и ставить/дропать null/default. Если такое решение нормальное, то готов решить задачу. |
@samdark As by the suggestions suggested above by many such as @mkiselev nothing works.
@samdark This is the applied and tried part of code which works perfectly with Defaults and Not Null.
This is the perfect , applied and tested code for the type errors in QueryBuilder. Where this makes the database independent queries. |
2.0.14 has the question also?
default value=>null |
Hello,
In user table I have column: status currently NULL is set and default value not set
This is how the migration looks:
$this->alterColumn('user', 'status', $this->string()->notNull()->defaultValue(10));
and this is the error:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "NOT"
LINE 1: ... TABLE "user" ALTER COLUMN "status" TYPE smallint NOT NULL D...
^
The SQL being executed was: ALTER TABLE "user" ALTER COLUMN "status" TYPE smallint NOT NULL DEFAULT 10
And
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "DEFAULT"
LINE 1: ... TABLE "user" ALTER COLUMN "status" TYPE smallint DEFAULT 10
^
The SQL being executed was: ALTER TABLE "user" ALTER COLUMN "status" TYPE smallint DEFAULT 10
Of course, I can change the column manually:
ALTER TABLE "user" ALTER COLUMN "status" ,ALTER COLUMN "status" SET NOT NULL,ALTER COLUMN "status" SET DEFAULT NULL;
but I'm interested why this doesn't work.
The text was updated successfully, but these errors were encountered: