Unfortunately, the material provided Is not enough for suggesting anything useful at once.
From my experience, a similar errors occurred when incorrectly linking tables. Try again to go through the script code and analyze what happens to the tables as they linking, whether multiple keys or circular references are generated.
Comment out all the script code and start adding one by one table in sequence, removing part of comment and analyzing the result in the "View data model" window after each part of comment is deleted. At a minimum, you will find point of code where the memory runs out when loading, and an error is output.