MariaDB - new database: table create error

Hi,

using HA docker installation 2022.8.4 at Pi.
Have created MariaDB server with database and user, is running fine - but after starting HA the tables will not be created.
I get the error:

Error during connection setup: (MySQLdb.OperationalError) (1005, 'Can\'t create table [DB_Name].states (errno: 150 "Foreign key constraint is incorrectly formed")')

[SQL: 
CREATE TABLE states (
	state_id INTEGER NOT NULL AUTO_INCREMENT, 
	entity_id VARCHAR(255), 
	state VARCHAR(255), 
	attributes LONGTEXT, 
	event_id INTEGER, 
	last_changed DATETIME(6), 
	last_updated DATETIME(6), 
	old_state_id INTEGER, 
	attributes_id INTEGER, 
	context_id VARCHAR(36), 
	context_user_id VARCHAR(36), 
	context_parent_id VARCHAR(36), 
	origin_idx SMALLINT, 
	PRIMARY KEY (state_id), 
	FOREIGN KEY(event_id) REFERENCES events (event_id) ON DELETE CASCADE, 
	FOREIGN KEY(old_state_id) REFERENCES states (state_id), 
	FOREIGN KEY(attributes_id) REFERENCES state_attributes (attributes_id)
)DEFAULT CHARSET=utf8mb4 COLLATE utf8mb4_unicode_ci

]

What can be the problem?
db_url is ok because some tables will be created:

+---------------------+
| Tables_in_[DB_Name] |
+---------------------+
| event_data          |
| events              |
| recorder_runs       |
| schema_changes      |
+---------------------+
4 rows in set (0.001 sec)

Thanks!
Michael