title: Grails Datasources "Cannot add or update a child row: a foreign key constraint fails"
body: <p>I'm using the Grails Datasources plugin in my app, and am having issues persisting a (chidl) domain class referencing a readonly association (parent) class. For example:</p>
  
  <pre><code>/* Parent domain class; a read-only datasource using the Datasources plugin */
  class Parent {
    //...Some fields
  }
  
  /* Child domain class, referencing the parent class */
  class Child
    // Some fields
    static hasOne = [parent:Parent]
  }
  </code></pre>
  
  <p>When I try and persist my child class, I get this error</p>
  
  <pre><code>Cannot add or update a child row: a foreign key constraint fails 
  (`foo`.`child`, CONSTRAINT `FK38A5EE5F707D1A2B` 
  FOREIGN KEY (`id`) REFERENCES `parent` (`id`))
  </code></pre>
  
  <p>I noticed that Grails creates a local, empty copy of the referenced table from (readonly) <code>datasource A</code> to my local (writeable) <code>datasource B</code> when the tables are created on startup. Could it be referencing this table (and its newly created FK) instead? If so, why does it not enforce the FK constraint on the actual datasource (i.e. in <code>datasource A</code>)?</p>
  
  <p>I'm fairly new to Grails, and have been unable to find solutions to this specific issue anywhere else, so sorry if this sounds like a stupid question</p>