<p>They key is to get the database from the "backup database" function in the control panel that includes</p>

<p>DROP TABLE IF EXISTS <code>craft_analytics_settings</code>;
...</p>

<p>before it creates all the tables so you shouldn't have to delete any tables first, been working for us that way since the beginning.</p>

CC BY-SA 3.0
2014-06-12T21:00:41.420Z
2014-06-12T21:00:41.420Z
Keith Mancuso
<p>The short answer is, <strong>yes, definitely drop your existing tables before importing a new .sql file.</strong> If you don't, you run a high risk of Craft developing weird issues of data mismatching. This is especially true if the two versions of the database were not created with the same exact version number of Craft.</p>

<p><strong>NOTE: You may want to back up your existing database before dropping all of the tables.</strong></p>

<p>The longer answer is, database syncing is an interesting and complicated problem, with many possible solutions. Check out this thread discussing the "holy grail" of database syncing across multiple environments...</p>

<p><a href="https://craftcms.stackexchange.com/questions/10/whats-the-best-practice-for-handling-data-migration-and-organization-across-dev">What&#39;s the best practice for handling data migration and organization across development environments?</a></p>

<p>Ultimately, your data migration patterns are up to you. There are varying approaches, some involving Shell scripts and Git hooks. It's an evolving challenge for the Craft community (and other CMS's as well), so keep your eyes peeled for the next brilliant "eureka" moment!</p>

CC BY-SA 3.0
2014-06-12T21:11:57.393Z
+1 on "Craft developing weird issues of data mismatching". Spent about two hours troubleshooting once, bothered Brad and Brandon, and now I'll never forget to clear out the whole database before importing.
Matt Stein
CC BY-SA 3.0
2014-06-12T20:58:46.690Z
2014-06-12T20:58:46.690Z
2017-04-13T12:51:00.200Z
Lindsey D
<p>Our team's typical workflow is pull from repo, delete craft tables, import latest db backup, work locally.</p>

<p>We don't want everyone working on the dev server db for early development, because we'll be breaking the site too much for everyone else.</p>

<p>Which brings me to my question, should I be deleting tables before importing? If I don't delete the tables Craft has to do some cleanup magic on the backend (I don't know what it does). I do know that Craft creates tables for matrix types. Would not deleting tables potentially leave orphaned db tables? Obviously there could other side effects as well.</p>

<p>Opinions? Clarification?</p>

CC BY-SA 3.0
2014-06-12T20:55:44.037Z
Not exactly duplicates, but there are two relevant questions that have seen some activity already: http://craftcms.stackexchange.com/questions/10/whats-the-best-practice-for-handling-data-migration-and-organization-across-dev?rq=1 and http://craftcms.stackexchange.com/questions/13/whats-the-best-practice-for-upgrading-a-versioned-craft-site.
Matt Stein
<back-up>
Best practice on importing Craft db backups?
# Best practice on importing Craft db backups?

(Asked by: username_0 on 2014-06-12)

Our team's typical workflow is pull from repo, delete craft tables, import latest db backup, work locally.

We don't want everyone working on the dev server db for early development, because we'll be breaking the site too much for everyone else.

Which brings me to my question, should I be deleting tables before importing? If I don't delete the tables Craft has to do some cleanup magic on the backend (I don't know what it does). I do know that Craft creates tables for matrix types. Would not deleting tables potentially leave orphaned db tables? Obviously there could other side effects as well.

Opinions? Clarification?

**Tags:** back-up

> **Comments:**
> **username_1**: Not exactly duplicates, but there are two relevant questions that have seen some activity already: http://craftcms.stackexchange.com/questions/10/whats-the-best-practice-for-handling-data-migration-and-organization-across-dev?rq=1 and http://craftcms.stackexchange.com/questions/13/whats-the-best-practice-for-upgrading-a-versioned-craft-site.  

---

## 2 answers

### Answer by username_3 on 2014-06-12. Score: 10 | Accepted answer

The short answer is, **yes, definitely drop your existing tables before importing a new .sql file.** If you don't, you run a high risk of Craft developing weird issues of data mismatching. This is especially true if the two versions of the database were not created with the same exact version number of Craft.

**NOTE: You may want to back up your existing database before dropping all of the tables.**

The longer answer is, database syncing is an interesting and complicated problem, with many possible solutions. Check out this thread discussing the "holy grail" of database syncing across multiple environments...

[What's the best practice for handling data migration and organization across development environments?](https://craftcms.stackexchange.com/questions/10/whats-the-best-practice-for-handling-data-migration-and-organization-across-dev)

Ultimately, your data migration patterns are up to you. There are varying approaches, some involving Shell scripts and Git hooks. It's an evolving challenge for the Craft community (and other CMS's as well), so keep your eyes peeled for the next brilliant "eureka" moment!

> **Comments:**
> **username_1**: +1 on "Craft developing weird issues of data mismatching". Spent about two hours troubleshooting once, bothered Brad and Brandon, and now I'll never forget to clear out the whole database before importing.  

---

### Answer by username_2 on 2014-06-12. Score: 2

They key is to get the database from the "backup database" function in the control panel that includes

DROP TABLE IF EXISTS `craft_analytics_settings`;
...

before it creates all the tables so you shouldn't have to delete any tables first, been working for us that way since the beginning.


---

