<p>This is to resolve a problem in which a <code>CREATE TABLE</code> is generated that MySQL rejects with a duplicate key name error.</p>
<p>When we create a foreign key constraint for MySQL we also create an index if there is not already an index beginning with the field in question. UNIQUEness constraints are implemented by indices, and so we can skip adding an index if one already exists.</p>
<p>To avoid changing existing working schemas, this change only skips index creation if one with the same name already exists. This case currently fails with a duplicate key error in MySQL, eg.,</p>
<p><code>ERROR 1061 (42000): Duplicate key name 'foo'</code></p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>&nbsp;&nbsp;<a href='https://github.com/dbsrgits/sql-translator/pull/121'>https://github.com/dbsrgits/sql-translator/pull/121</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>Assert current behaviour with clashing index names</li>
  <li>Avoid index name clashing with UNIQUE KEY</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/dbsrgits/sql-translator/pull/121/files#diff-0">lib/SQL/Translator/Producer/MySQL.pm</a>
    (10)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/dbsrgits/sql-translator/pull/121/files#diff-1">t/38-mysql-producer.t</a>
    (45)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/dbsrgits/sql-translator/pull/121.patch'>https://github.com/dbsrgits/sql-translator/pull/121.patch</a></li>
  <li><a href='https://github.com/dbsrgits/sql-translator/pull/121.diff'>https://github.com/dbsrgits/sql-translator/pull/121.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">&mdash;<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/dbsrgits/sql-translator/pull/121?email_source=notifications&amp;email_token=AACJ4AW3F5SUHZG3MQLYNNDQYIVPTA5CNFSM4JZ52IX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IABG7ZA">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AACJ4AXU366RCGNKZG7EAATQYIVPTANCNFSM4JZ52IXQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AACJ4ASDRYSYFPMAXCRPZTTQYIVPTA5CNFSM4JZ52IX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IABG7ZA.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/dbsrgits/sql-translator/pull/121?email_source=notifications\u0026email_token=AACJ4AW3F5SUHZG3MQLYNNDQYIVPTA5CNFSM4JZ52IX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IABG7ZA",
"url": "https://github.com/dbsrgits/sql-translator/pull/121?email_source=notifications\u0026email_token=AACJ4AW3F5SUHZG3MQLYNNDQYIVPTA5CNFSM4JZ52IX2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4IABG7ZA",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>