title: _mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')
body: <p>I use the Ontonotes DB tools, but I encounter a problem.</p>
  
  <p>I read its document, and it say that this tool works well on mysql 5.0. However, I can't find this version. So, I install mysql 5.7. This problem appears, and the problem is like this:</p>
  
  <pre><code>python on/tools/init_db.py --init ontonotes localhost root ontonotes-release-4.0/
  </code></pre>
  
  <p>Initializing DB...</p>
  
  <blockquote>
    <p>/Users/anaconda/lib/python2.7/site-packages/on/<strong>init</strong>.py:525:
    Warning: Unknown table 'ontonotes.tree'   cursor.execute("""drop table
    if exists %s;""" % thing.sql_table_name)</p>
  </blockquote>
  
  <pre><code>create table tree
  (
    id                  varchar(255) not null collate utf8_bin primary key,
    parent_id           varchar(255),
    document_id         varchar(255),
    word                varchar(255),
    child_index         int,
    start               int not null,
    end                 int not null,
    coref_section       int not null,
    syntactic_link_type varchar(255),
    tag                 varchar(255) not null,
    part_of_speech      varchar(255),
    phrase_type         varchar(255),
    function_tag_id     varchar(255),
    string              longtext,
    no_trace_string     longtext,
    parse               longtext,
    foreign key (parent_id)           references tree.id,
    foreign key (document_id)         references document.id,
    foreign key (syntactic_link_type) references syntactic_link_type.id,
    foreign key (part_of_speech)      references pos_type.id,
    foreign key (phrase_type)         references phrase_type.id,
    foreign key (function_tag_id)     references compound_function_tag.id
  )
  default character set utf8;
  </code></pre>
  
  <blockquote>
    <p>Traceback (most recent call last):   File "on/tools/init_db.py", line
    81, in 
        on.ontonotes.initialize_db(a_cursor)   File "/Users/anaconda/lib/python2.7/site-packages/on/<strong>init</strong>.py", line
    528, in initialize_db
        cursor.execute(thing.sql_create_statement)   File "/Users/anaconda/lib/python2.7/site-packages/MySQLdb/cursors.py", line
    205, in execute
        self.errorhandler(self, exc, value)   File "/Users/anaconda/lib/python2.7/site-packages/MySQLdb/connections.py",
    line 36, in defaulterrorhandler
        raise errorclass, errorvalue
    _mysql_exceptions.IntegrityError: (1215, 'Cannot add foreign key constraint')</p>
  </blockquote>
  
  <p>and there three table have been created:</p>
  
  <pre><code>create table ontonotes
  (
     id varchar(255) not null primary key
  
  )
  default character set utf8;
  
  
  create table subcorpus
  (
    id varchar(255) not null primary key,
    base_dir varchar(255) not null,
    top_dir varchar(255) not null,
    root_dir varchar(255) not null,
    language_id varchar(255) not null,
    encoding_id varchar(255) not null,
    ontonotes_id varchar(255) not null
  
  )
  default character set utf8;
  
  create table file
  (
    id varchar(255) not null primary key,
    base_dir varchar(255) not null,
    physical_filename varchar(255) not null,
    document_id varchar(255) not null,
    file_type varchar(255) not null,
    subcorpus_id varchar(255) not null
  )
  default character set utf8;
  </code></pre>
  
  <p>I really don't know how to solve this problem, because I'm not familiar with mysql. Can someone help me, or give me a mysql 5.0 version (linux 64bit/mac 64bit)? Think you very much!</p>