Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have to migrate some data from one MySQL database to another one, both credentials are in the Django app settings file, accessible and everything is OK.

My setting file is like this:

DATABASES = {
'default': {
    'NAME': 'app_data',
    'ENGINE': 'django.db.backends.mysql',
    'USER': 'mysql_user',
    'PASSWORD': 's3krit'
},
'prod_old': {
    'NAME': 'old_app_data',
    'ENGINE': 'django.db.backends.mysql',
    'USER': 'mysql_user',
    'PASSWORD': 'priv4te'
}
}

What i am think so for: document = Document.objects.using('prod_old').get(id=i) then create another object in the default database using just Document() without specifying the DB (Django will use the default). If i call Document().save() do the ID coming from the using('prod_old') get copied to the "Default DB" ?

Can't find anything clear on this situation ! Thanks for the help !

share|improve this question

2 Answers 2

Try with this:

python manage.py dumpdata --database=default > old-fixture
python manage.py loaddata --database=pro_old old-fixture
share|improve this answer
    
just be sure that both database have the same tables –  juliocesar Nov 22 '13 at 17:58
    
thanks for the suggestion, this is not what i need, I just have to move some entries on the Documents table, not all of it, and before migrating it, i'll have to add some additional data. –  e-nouri Nov 22 '13 at 23:36
up vote 0 down vote accepted

The solution is to initiate the class Document justCreatedDocument = Document(), and then call save() that will give it an auto-incremented ID in the database, then you have to save that ID, copy the object with justCreatedDocument = oldDocument and replace the ID with the one you copied, or the Document will be saved with an arbitrary ID.

This is the only solution I found !

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.