Altering primary key of a table

You can modify the existing primary key using the API console or via the API.

Head to the Data > SQL section of API console and execute the following SQl query.

ALTER TABLE category
   DROP CONSTRAINT category_pkey;
ALTER TABLE category
   ADD PRIMARY KEY (name);

Note

Check the This is a migration checkbox to retain the query as a migration.

First, you have to drop the existing primary key constraint before adding the new one. If you don’t have a primary key already, then skip the DROP CONSTRAINT statement in the above query.

POST data.<cluster-name>.hasura-app.io/v1/query HTTP/1.1
Content-Type: application/json
Authorization: Bearer <auth-token> # optional if cookie is set
X-Hasura-Role: admin

{
   "type" : "run_sql",
   "args" : {
     "sql" : "ALTER TABLE category
          DROP CONSTRAINT category_pkey;
          ALTER TABLE category
          ADD PRIMARY KEY (name);"
   }
}

First, you have to drop the existing primary key constraint before adding the new one. If you don’t have a primary key already, then skip the DROP CONSTRAINT statement in the above API.

Note

You cannot retain the query as a migration using the API