2019-11-08

How to add empty string as default value for text field in Hasura

elitasson's avatar on Twitter
Johan Eliasson

Let's say we have a table posts and we want to add a new column tag which should be an empty string by default.

Hasura console
Hasura console

We can not add our tag text field with a default empty string using the Hasura console's "Add a new column". Instead we must add the column manually to the PostgreSQL database.

Click on SQL in the left menu in the Hasura console to insert the following SQL statement:

ALTER TABLE "posts" ADD COLUMN "tag" text NOT NULL DEFAULT '';
Adding column tag to table posts
Adding column tag to table posts

Click Run. Your new tag column with a default empty string is added to the posts table!

What's next?
Did you find this blog post interesting? Follow me on Twitter where I write more about my journey with Nhost.
Try Nhost for Free Today
Focus on your app and your users!

The Jamstack backend with Hasura.

Product
Build
Coming soon
Resources
Company
© Nhost
githubtwitterdiscordyoutubelinkedin