Users' timetable database
From looking at your database description . . .


No unique constraint on Users.username. You can have 1000 users named "Fred".
No unique constraint on Groups.groupname. You can have 1000 groups named "Hamburger". You probably don't want to allow that.
If you intend to build Membership like UserID integer not null unique references Users (userID), and GroupID integer not null unique references Groups (GroupID) then each user and each group can appear in that table only once. That means that if I have membership in the group Hamburger, you cannot also have membership in the group Hamburger. I think you probably want to drop the UNIQUE constraint from both those clauses, and add PRIMARY KEY (UserID, GroupID).
It's not clear what the difference is between the two tables Membership and Group.


From looking at your code . . .


db.QueryValue("SELECT user_id FROM users WHERE username = name"); You're selecting user identifiers given the users' names. But names aren't unique in your database. If I select one "Fred", and there are 1000 Freds in your database, I'm going to end up with 1000 different user identifiers. You probably don't want to do this.
db.Execute("INSERT INTO group(groupName) There's no column named "groupname" in that table.
int groupID = db.QueryValue("SELECT groupid from group where groupname = You're selecting group identifiers given the group's name. Same problem as with selecting user identifiers above.


Unless I misunderstand you, and that's always possible, you should be able to insert existing users and existing groups into Memberships with a single INSERT statement.