I have a table `containers` that can have a many-to-many relationships to several tables, let's say those are `plants`, `animals` and `bacteria`. Each container can contain an arbitrary number of plants, animals or bacteria, and each plant, animal or bacterium can be in an arbitrary number of containers.

So far this is very straightforward, but the part I'm having a problem with is that each container should only contain elements of the same type. Mixed containers that e.g. contain both plants and animals should be a constraint violation in the database.

My original schema for this was the following:

```
containers
----------
id
...
...

containers_plants
-----------------
container_id
plant_id

containers_animals
------------------
container_id
animal_id

containers_bacteria
-------------------
container_id
bacterium_id

```

But with this schema, I can't come up with how to implement the constraint that containers should be homogeneous. 

Is there a way to implement this with referential integrity and ensuring on the database level that the containers are homogeneous?

I'm using Postgres 9.6 for this.