-
-
Notifications
You must be signed in to change notification settings - Fork 48
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
[INFO] django-redshift-backend cannot provide change column for: PRIMARY, UNIQUE, FK, NOT NULL #96
Comments
How to ADD COLUMN NOT NULL without DEFAULT? You can't. Alternative:
|
How to modify NOT NULL to NULL ? (#63) You can't DROP NOT NULL as:
Alternative flow:
Note that, redshift in transaction can't rename column:
|
How to change default? You can't DROP DEFAULT / SET DEFAULT as:
Alternative flow:
Note that, redshift in transaction can't rename column:
|
How to change type (varchar size) with UNIQUE constraint? You can't change type for UNIQUE.
However, once drop constraints of the column, you can.
|
How to change type (varchar size) with PRIMARY KEY constraint? You can't change type for PRIMARY KEY. dev=# CREATE TABLE pony (name varchar(20) PRIMARY KEY);
CREATE TABLE
dev=# \d pony;
Table "public.pony"
Column | Type | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
name | character varying(20) | | not null |
Indexes:
"pony_pkey" PRIMARY KEY, btree (name)
dev=# ALTER TABLE pony ALTER COLUMN name TYPE varchar(30);
ERROR: cannot alter type of a column which is primary or foreign key or unique However, once drop constraints of the column, you can. dev=# ALTER TABLE pony DROP CONSTRAINT pony_pkey;
ALTER TABLE
dev=# ALTER TABLE pony ALTER COLUMN name TYPE varchar(30);
ALTER TABLE
dev=# ALTER TABLE pony ADD PRIMARY KEY (name);
ALTER TABLE
dev=# \d pony
Table "public.pony"
Column | Type | Collation | Nullable | Default
--------+-----------------------+-----------+----------+---------
name | character varying(30) | | not null |
Indexes:
"pony_pkey" PRIMARY KEY, btree (name) |
How to change type (varchar size) with FOREIGN KEY constraint? dev=# ALTER TABLE pony ADD COLUMN name_ref varchar(30);
ALTER TABLE
dev=# ALTER TABLE pony ADD FOREIGN KEY (name_ref) REFERENCES pony (name);
ALTER TABLE
dev=# \d pony
Table "public.pony"
Column | Type | Collation | Nullable | Default
----------+-----------------------+-----------+----------+---------
name | character varying(30) | | not null |
name_ref | character varying(30) | | |
Indexes:
"pony_pkey" PRIMARY KEY, btree (name)
Foreign-key constraints:
"pony_name_ref_fkey" FOREIGN KEY (name_ref) REFERENCES pony(name)
Referenced by:
TABLE "pony" CONSTRAINT "pony_name_ref_fkey" FOREIGN KEY (name_ref) REFERENCES pony(name)
dev=# ALTER TABLE pony ALTER COLUMN name_ref TYPE varchar(40);
ERROR: cannot alter type of a column which is primary or foreign key or unique |
RENAME and TYPE change in a transaction is not allowed. dev=# alter table pony add column ba varchar(10) NULL;
ALTER TABLE
dev=# begin;
BEGIN
dev=# alter table pony alter column ba type varchar(20);
ERROR: current transaction is aborted, commands ignored until end of transaction block
dev=# alter table pony rename column ba to bar;
ERROR: current transaction is aborted, commands ignored until end of transaction block
dev=# end;
ROLLBACK
dev=# alter table pony alter column ba type varchar(20);
ALTER TABLE
dev=# alter table pony rename column ba to bar;
ALTER TABLE |
How to change type (varchar size) with default value? Redshift says:
However, we can migrate into new column.
|
How to change type (varchar size) with unique constraint? Redshift says:
However, we can migrate into new column.
|
Redshift backend cannot provide the following features
In Redshift, these are only possible when creating a new table.
The alternative is to recreate the table and insert data into the new table from old table. However, this process cannot be provided as a feature of django-redshift-backend because it is too difficult to perform this process with automatic migration and the impact of failure would be significant.
For more information, please refer to the following page.
https://docs.aws.amazon.com/en_us/redshift/latest/dg/r_ALTER_TABLE.html
NOTE:
The text was updated successfully, but these errors were encountered: