diff --git a/patches/patch20221122-6.0-SNAPSHOT/create_entity_ids_table.sql b/patches/patch20221122-6.0-SNAPSHOT/create_entity_ids_table.sql
index 5b07ce82d89619149ac615aeccd69747b2f55418..72356921a8cffa0d734f2b1394f4d54d46a78d8b 100644
--- a/patches/patch20221122-6.0-SNAPSHOT/create_entity_ids_table.sql
+++ b/patches/patch20221122-6.0-SNAPSHOT/create_entity_ids_table.sql
@@ -6,6 +6,8 @@ DROP PROCEDURE IF EXISTS getInfo;
 DROP PROCEDURE IF EXISTS getRole;
 DROP PROCEDURE IF EXISTS setPassword;
 DROP PROCEDURE IF EXISTS initAutoIncrement;
+DELETE FROM name_data WHERE entity_id=50;
+DELETE FROM entities WHERE id=50;
 DELETE FROM entities WHERE id=99;
 
 
@@ -16,13 +18,13 @@ CREATE TABLE `entity_ids` (
     `internal_id` int(10) unsigned NOT NULL COMMENT 'Internal ID of an entity. This id is used internally in the *_data tables and elsewhere. This ID is never exposed via the CaosDB API.',
     PRIMARY KEY `entity_ids_pk` (`id`),
     CONSTRAINT `entity_ids_internal_id` FOREIGN KEY (`internal_id`) REFERENCES `entities` (`id`)
-) ENGINE=InnoDB;
+) ENGINE=InnoDB COLLATE utf8mb4_bin;
 
 -- fill all existing entities into the new entity_ids table.
-INSERT INTO entity_ids (id, internal_id) SELECT id, id FROM entities WHERE id>0 AND role!="DOMAIN" AND id!=50;
+INSERT INTO entity_ids (id, internal_id) SELECT id, id FROM entities WHERE id>0 AND role!="DOMAIN";
 
-ALTER TABLE transaction_log MODIFY COLUMN `entity_id` VARCHAR(255) NOT NULL;
+ALTER TABLE transaction_log MODIFY COLUMN `entity_id` VARCHAR(255) COLLATE utf8mb4_bin NOT NULL;
 
 ALTER TABLE user_info DROP CONSTRAINT `subjects_ibfk_1`;
-ALTER TABle user_info MODIFY COLUMN `entity` VARCHAR(255) DEFAULT NULL;
+ALTER TABle user_info MODIFY COLUMN `entity` VARCHAR(255) COLLATE utf8mb4_bin DEFAULT NULL;
 ALTER TABLE user_info ADD CONSTRAINT `subjects_ibfk_2` FOREIGN KEY (`entity`) REFERENCES `entity_ids` (`id`);
diff --git a/procedures/entityVersioning.sql b/procedures/entityVersioning.sql
index 84369294f4700eed31f3241c04272bf2a3034960..155ab7e45c204e4fb9f74eb647f5d0311e83792b 100644
--- a/procedures/entityVersioning.sql
+++ b/procedures/entityVersioning.sql
@@ -62,7 +62,7 @@ BEGIN
         IF newipparent IS NULL THEN
             -- throw error;
             SELECT concat("This parent does not exists: ", Parent)
-            FROM nonexisting;
+            FROM parent_version_does_not_exist;
         END IF;
     END IF;
 
diff --git a/tests/test_autotap.sql b/tests/test_autotap.sql
index 8afd5cd56d171db2c4e800ed09f9180c2e45bd2d..acaa8967028151b28bf5b7003a64164f0ce70474 100644
--- a/tests/test_autotap.sql
+++ b/tests/test_autotap.sql
@@ -1914,11 +1914,11 @@ SELECT tap.col_collation_is('_caosdb_schema_unit_tests','transaction_log','trans
 -- COLUMN transaction_log.entity_id
 
 SELECT tap.has_column('_caosdb_schema_unit_tests','transaction_log','entity_id','');
-SELECT tap.col_column_type_is('_caosdb_schema_unit_tests','transaction_log','entity_id','int(10) unsigned','');
+SELECT tap.col_column_type_is('_caosdb_schema_unit_tests','transaction_log','entity_id','varchar(255)','');
 SELECT tap.col_extra_is('_caosdb_schema_unit_tests','transaction_log','entity_id','','');
 SELECT tap.col_default_is('_caosdb_schema_unit_tests','transaction_log','entity_id',NULL,'');
-SELECT tap.col_charset_is('_caosdb_schema_unit_tests','transaction_log','entity_id',NULL,'');
-SELECT tap.col_collation_is('_caosdb_schema_unit_tests','transaction_log','entity_id',NULL,'');
+SELECT tap.col_charset_is('_caosdb_schema_unit_tests','transaction_log','entity_id','utf8mb4','');
+SELECT tap.col_collation_is('_caosdb_schema_unit_tests','transaction_log','entity_id','utf8mb4_bin','');
 
 -- COLUMN transaction_log.username
 
@@ -2089,11 +2089,11 @@ SELECT tap.col_collation_is('_caosdb_schema_unit_tests','user_info','status','ut
 -- COLUMN user_info.entity
 
 SELECT tap.has_column('_caosdb_schema_unit_tests','user_info','entity','');
-SELECT tap.col_column_type_is('_caosdb_schema_unit_tests','user_info','entity','int(10) unsigned','');
+SELECT tap.col_column_type_is('_caosdb_schema_unit_tests','user_info','entity','varchar(255)','');
 SELECT tap.col_extra_is('_caosdb_schema_unit_tests','user_info','entity','','');
 SELECT tap.col_default_is('_caosdb_schema_unit_tests','user_info','entity','NULL','');
-SELECT tap.col_charset_is('_caosdb_schema_unit_tests','user_info','entity',NULL,'');
-SELECT tap.col_collation_is('_caosdb_schema_unit_tests','user_info','entity',NULL,'');
+SELECT tap.col_charset_is('_caosdb_schema_unit_tests','user_info','entity','utf8mb4','');
+SELECT tap.col_collation_is('_caosdb_schema_unit_tests','user_info','entity','utf8mb4_bin','');
 
 -- INDEXES
 SELECT tap.indexes_are('_caosdb_schema_unit_tests','user_info','`subject_entity`','');
@@ -2105,7 +2105,7 @@ SELECT tap.index_is_type('_caosdb_schema_unit_tests','user_info','subject_entity
 SELECT tap.is_indexed('_caosdb_schema_unit_tests','user_info','`entity`','');
 
 -- CONSTRAINTS
-SELECT tap.constraints_are('_caosdb_schema_unit_tests','user_info','`PRIMARY`,`subjects_ibfk_1`','');
+SELECT tap.constraints_are('_caosdb_schema_unit_tests','user_info','`PRIMARY`,`subjects_ibfk_2`','');
 
 -- CONSTRAINT user_info.PRIMARY
 
@@ -2115,10 +2115,10 @@ SELECT tap.col_is_pk('_caosdb_schema_unit_tests','user_info','`realm`,`name`',''
 
 -- CONSTRAINT user_info.subjects_ibfk_1
 
-SELECT tap.has_constraint('_caosdb_schema_unit_tests','user_info','subjects_ibfk_1','');
-SELECT tap.constraint_type_is('_caosdb_schema_unit_tests','user_info','subjects_ibfk_1','FOREIGN KEY','');
-SELECT tap.fk_on_delete('_caosdb_schema_unit_tests','user_info','subjects_ibfk_1','RESTRICT','');
-SELECT tap.fk_on_update('_caosdb_schema_unit_tests','user_info','subjects_ibfk_1','RESTRICT','');
+SELECT tap.has_constraint('_caosdb_schema_unit_tests','user_info','subjects_ibfk_2','');
+SELECT tap.constraint_type_is('_caosdb_schema_unit_tests','user_info','subjects_ibfk_2','FOREIGN KEY','');
+SELECT tap.fk_on_delete('_caosdb_schema_unit_tests','user_info','subjects_ibfk_2','RESTRICT','');
+SELECT tap.fk_on_update('_caosdb_schema_unit_tests','user_info','subjects_ibfk_2','RESTRICT','');
 
 -- ***************************************************************
 -- TABLE _caosdb_schema_unit_tests.user_roles
@@ -2509,13 +2509,6 @@ SELECT tap.procedure_is_deterministic('_caosdb_schema_unit_tests','getFileIdByPa
 SELECT tap.procedure_security_type_is('_caosdb_schema_unit_tests','getFileIdByPath','DEFINER','');
 SELECT tap.procedure_sql_data_access_is('_caosdb_schema_unit_tests','getFileIdByPath','CONTAINS SQL','');
 
--- PROCEDURES _caosdb_schema_unit_tests.initAutoIncrement
-
-SELECT tap.has_procedure('_caosdb_schema_unit_tests','initAutoIncrement','');
-SELECT tap.procedure_is_deterministic('_caosdb_schema_unit_tests','initAutoIncrement','NO','');
-SELECT tap.procedure_security_type_is('_caosdb_schema_unit_tests','initAutoIncrement','DEFINER','');
-SELECT tap.procedure_sql_data_access_is('_caosdb_schema_unit_tests','initAutoIncrement','CONTAINS SQL','');
-
 -- PROCEDURES _caosdb_schema_unit_tests.initBackReference
 
 SELECT tap.has_procedure('_caosdb_schema_unit_tests','initBackReference','');
diff --git a/tests/test_reference_values.sql b/tests/test_reference_values.sql
index 47b4db4d33cd7e841da610aca886a3d6bd4947d3..34376a8a2e28d5b02b4cb91e239a6cdd32a6fd54 100644
--- a/tests/test_reference_values.sql
+++ b/tests/test_reference_values.sql
@@ -37,9 +37,14 @@ INSERT INTO transactions (srid,seconds,nanos,username,realm) VALUES
 ("SRIDbla", 1234, 2345, "me", "home"),
 ("SRIDblub", 2345, 3465, "me", "home"),
 ("SRIDblieb", 3456, 4576, "you", "home");
-SET @EntityID=99;
+SET @EntityID="99";
 SET @PropertyID=11;
 SET @Value=50;
+SET @SRID="SRIDbla";
+call insertEntity(@EntityID, "TheName", "TheDesc", "RecordType", "{}");
+call insertEntity(@Value, "RefValue", "ValueDesc", "Record", "{}");
+SELECT internal_id INTO @InternalEntityID FROM entity_ids WHERE id = @EntityID;
+SELECT internal_id INTO @InternalValueID FROM entity_ids WHERE id = @Value;
 
 -- switch off versioning
 DELETE FROM feature_config WHERE _key = "ENTITY_VERSIONING";
@@ -49,16 +54,16 @@ CALL insertEntityProperty(0, @EntityID, @PropertyID, "reference_data", @Value,
     NULL, "FIX", NULL, NULL, NULL, NULL, 0);
 
 -- TODO switch expected/actual
-SELECT tap.eq(0, domain_id, "domain ok") FROM reference_data;
-SELECT tap.eq(99, entity_id, "entity ok") FROM reference_data;
-SELECT tap.eq(11, property_id, "property ok") FROM reference_data;
-SELECT tap.eq(50, value, "value ok") FROM reference_data;
+SELECT tap.eq("0", domain_id, "domain ok") FROM reference_data;
+SELECT tap.eq(@InternalEntityID, entity_id, "entity ok") FROM reference_data;
+SELECT tap.eq("11", property_id, "property ok") FROM reference_data;
+SELECT tap.eq(@InternalValueID, value, "value ok") FROM reference_data;
 SELECT tap.eq("FIX", status, "status ok") FROM reference_data;
 SELECT tap.eq("0", pidx, "pidx ok") FROM reference_data;
-SELECT tap.eq(NULL, value_iversion, "value_iversion ok") FROM reference_data;
+SELECT tap.eq(NULL, value_iversion, "value_iversion ok 1") FROM reference_data;
 
 -- clean up
-DELETE FROM reference_data WHERE domain_id=0 AND entity_id=99;
+DELETE FROM reference_data WHERE domain_id=0 AND entity_id=@InternalValueID;
 
 -- #####################################################################
 -- TODO TEST insertEntityProperty with Versioning
@@ -69,39 +74,43 @@ INSERT INTO feature_config (_key, _value) VALUES ("ENTITY_VERSIONING", "ENABLED"
 
 
 -- TEST insertEntityProperty with Versioning - REFERENCE HEAD
-SET @VALUE="50";
 CALL insertEntityProperty(0, @EntityID, @PropertyID, "reference_data", @Value,
     NULL, "FIX", NULL, NULL, NULL, NULL, 0);
 
 -- TODO switch expected/actual
 SELECT tap.eq(0, domain_id, "domain ok") FROM reference_data;
-SELECT tap.eq(99, entity_id, "entity ok") FROM reference_data;
+SELECT tap.eq(@InternalEntityID, entity_id, "entity ok") FROM reference_data;
 SELECT tap.eq(11, property_id, "property ok") FROM reference_data;
-SELECT tap.eq(50, value, "value ok") FROM reference_data;
+SELECT tap.eq(@InternalValueID, value, "value ok") FROM reference_data;
 SELECT tap.eq("FIX", status, "status ok") FROM reference_data;
 SELECT tap.eq("0", pidx, "pidx ok") FROM reference_data;
-SELECT tap.eq(value_iversion, NULL, "value_iversion ok") FROM reference_data;
+SELECT tap.eq(value_iversion, NULL, "value_iversion ok 2") FROM reference_data;
 
-DELETE FROM reference_data WHERE domain_id=0 AND entity_id=99;
+DELETE FROM reference_data WHERE domain_id=0 AND entity_id=@InternalEntityID;
 
 
 -- TEST insertEntityProperty with Versioning - Reference version
-CALL insert_single_child_version(50, "hashbla", "versionbla", NULL, "SRIDbla");
-CALL insert_single_child_version(50, "hashblub", "versionblub", "versionbla", "SRIDblub");
-
-SET @VALUE="50@versionbla";
+SELECT * FROM entity_ids;
+SELECT * FROM entity_version;
+SELECT e.version INTO @ParentVersion
+    FROM entity_version as e
+    WHERE e.entity_id = @InternalValueID
+    AND e._iversion = 1;
+CALL insert_single_child_version(@InternalValueID, "hashblub", "versionblub", @ParentVersion, "SRIDblub");
+
+SET @VALUE=CONCAT("50@", @ParentVersion);
 CALL insertEntityProperty(0, @EntityID, @PropertyID, "reference_data", @Value,
     NULL, "FIX", NULL, NULL, NULL, NULL, 0);
 
 SELECT tap.eq(0, domain_id, "domain ok") FROM reference_data;
-SELECT tap.eq(99, entity_id, "entity ok") FROM reference_data;
+SELECT tap.eq(@InternalEntityID, entity_id, "entity ok") FROM reference_data;
 SELECT tap.eq(11, property_id, "property ok") FROM reference_data;
-SELECT tap.eq(50, value, "value ok") FROM reference_data;
+SELECT tap.eq(@InternalValueID, value, "value ok") FROM reference_data;
 SELECT tap.eq("FIX", status, "status ok") FROM reference_data;
 SELECT tap.eq("0", pidx, "pidx ok") FROM reference_data;
-SELECT tap.eq(value_iversion, "1", "value_iversion ok") FROM reference_data;
+SELECT tap.eq(value_iversion, "1", "value_iversion ok 3") FROM reference_data;
 
-DELETE FROM reference_data WHERE domain_id=0 AND entity_id=99;
+DELETE FROM reference_data WHERE domain_id=0 AND entity_id=@InternalEntityID;
 
 SET @VALUE="50@versionblub";
 CALL insertEntityProperty(0, @EntityID, @PropertyID, "reference_data", @Value,
@@ -109,12 +118,12 @@ CALL insertEntityProperty(0, @EntityID, @PropertyID, "reference_data", @Value,
 
 -- TODO switch expected/actual
 SELECT tap.eq(0, domain_id, "domain ok") FROM reference_data;
-SELECT tap.eq(99, entity_id, "entity ok") FROM reference_data;
+SELECT tap.eq(@InternalEntityID, entity_id, "entity ok") FROM reference_data;
 SELECT tap.eq(11, property_id, "property ok") FROM reference_data;
-SELECT tap.eq(50, value, "value ok") FROM reference_data;
+SELECT tap.eq(@InternalValueID, value, "value ok") FROM reference_data;
 SELECT tap.eq("FIX", status, "status ok") FROM reference_data;
 SELECT tap.eq("0", pidx, "pidx ok") FROM reference_data;
-SELECT tap.eq(value_iversion, "2", "value_iversion ok") FROM reference_data;
+SELECT tap.eq(value_iversion, "2", "value_iversion ok 4") FROM reference_data;
 
 
 -- invalid values throw errors