I'm coming from a MySQL world and am having a hard time doing things in PostgreSQL.
I have a column which looks like this in my GUI client:
I'm not sure if it is an enum column, or a varchar with a constraint (are they the same thing in postgres?)
I want to change the type of the column to a varchar/string. I've tried this:
ALTER TABLE tablename ALTER COLUMN type TYPE character varying(255);
but no luck, I still see the constraints on the column
Currently DROP CONSTRAINT drops only CHECK constraints. To remove a PRIMARY or UNIQUE constraint, drop the relevant index using the DROP INDEX command. To remove FOREIGN KEY constraints you need to recreate and reload the table, using other parameters to the CREATE TABLE command.
For modifying the column's default value, we can use the ALTER TABLE ALTER COLUMN SET DEFAULT or DROP DEFAULT command. ALTER TABLE table_name ALTER COLUMN column_name [SET DEFAULT value | DROP DEFAULT]; We will use ALTER TABLE ADD CONSTRAINT command for adding a constraint.
To drop a foreign key from a table, use the ALTER TABLE clause with the name of the table (in our example, student ) followed by the clause DROP CONSTRAINT with the name of the foreign key constraint.
I was able to solve this issue with some guidance from @mich4ael's helpful comment
ALTER TABLE tablename DROP CONSTRAINT constraint_name;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With