Foreign Key NULL vs Foreign Key to an empty string
The answer lies in the ambiguity of your question:

However if I want a unique index on medicine name &amp; brand_id ...

You do not actually want &quot;a unique index&quot;. You want to enforce certain rules. A unique index is a means to an end; a tool. The question is: What exactly do you want?
Do you want that there can only be a single instance of a name with an unknown brand? Or can there be multiple instances? That depends on what &quot;unknown&quot; or &quot;missing&quot; or &quot;empty&quot; or NULL is supposed to mean for you.
The canonical meaning of NULL is &quot;unknown&quot;. We simply do not know, what goes here, it could be anything, including nothing (empty ('') in string types, 0 in numeric types).
If you want to allow one generic brand, include an entry in brand, call it &quot;generic&quot; or &quot;ACME&quot; or whatever. I like to use the id value 0 for such a catch-all entry.
Then your unique index or constraint is doing what it's supposed to do: Allow only one instance of (name, brand_id) in the table medicine. But multiple entries with (name, NULL) are still possible. Set brand_id NOT NULL, too, if you don't want that.
The best solution also depends on typical queries and details of your setup. Be sure to document exactly what NULL / empty / 0 is supposed to mean and why you chose to design it like that. It may seem crystal clear at the moment you implement it, but may be confusing later.
I added another link to the answer you referenced:

PostgreSQL multi-column unique constraint and NULL values
Create unique constraint with null columns