簡體   English   中英

更改表以添加可為空為真的新列

[英]Altering table to add new column with nullable true

我正在用typeorm編寫遷移文件,我想在現有表中添加一個額外的列。 我正在編寫以下查詢

await queryRunner.query('ALTER TABLE "me" ADD COLUMN "id" VARCHAR(255) DEFAULT NULL');

使用上述查詢,我​​發現以下錯誤: RSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"me" ADD COLUMN "id" VARCHAR(255) DEFAULT NULL' at line 1 RSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"me" ADD COLUMN "id" VARCHAR(255) DEFAULT NULL' at line 1 ,`

我只是希望我的列可以為nullable ,我還想將Collation設置為utf8mb4_bin

我如何做到這一點?

不需要在表名和列名周圍加雙引號。

ALTER TABLE me ADD COLUMN id VARCHAR(255) DEFAULT NULL;

此外, id列通常是auto increment intprimary key字段。所以如果你想命名一個字符串字段id ,它可能不明確。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM