Allow backend & client SQL tests on mysql and pg.

Currently the tables are not created which means that it isn't
possible for these tests to run on anything other than sqlite.

Fix test issues where the token id that is used to create the token is
not the same as the id that the token is saved with.

Fix a number of foreign key constraints issues.

Bug  1178041

Change-Id: Ib67eb97836e4224940abdeae4bba66748bfe4ca5