Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Run this query in your database console: <code>SELECT *, COUNT(*) as n FROM table_name group by column_name HAVING n&gt;1</code></p></li> <li><p>Fix the duplicate rows</p></li> <li><p>Re-run your migration</p></li> </ol> <p>IMHO, you should edit your duplicate data manually so that you can be sure the data is correctly fixed.</p> <p><strong>Update:</strong></p> <p>OP didn't mention he/she is using Postgres and I gave a solution for MySQL.</p> <p>For Postgres:</p> <p>Based on this solution: <a href="https://stackoverflow.com/questions/14471179/find-duplicate-rows-with-postgresql">Find duplicate rows with PostgreSQL</a></p> <p>Run this query:</p> <pre><code>SELECT * FROM ( SELECT id, ROW_NUMBER() OVER(PARTITION BY merchant_Id, url ORDER BY id asc) AS Row FROM Photos ) dups WHERE dups.Row &gt; 1 </code></pre> <p><strong>More explanation:</strong></p> <p>In order for you to execute the migration and add unique constraint to your columns, you need to fix the current data first. Usually, there's no automatic step for this in order to make sure you won't end up with incorrect data. </p> <p>That's why you need to manually find the duplicate rows and fix it. The given query will show you which rows are duplicates. So, from there, fix the data and you should be able to run the migration.</p> <p><strong>Mooore update:</strong></p> <p>The duplicated rows do not get marked. For an example, if you get this kindo of result:</p> <pre><code>ID ROW 235 2 236 3 2 2 3 3 </code></pre> <p>You should select the row with <code>id=235</code> and then select every row with the same column value as <code>id=235</code>. From there, you'll see every <code>id</code> which are duplicates from <code>id=235</code>. Then, just edit them one by one.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload