last day (14 days later) » 

8:41 PM
0
Q: Duplicate column name when migrating Django database

Сергей ПотаповI am trying to migrate my database: E:\PhytonProgects\natarelke>python manage.py migrate System check identified some issues: WARNINGS: ?: (mysql.W002) MySQL Strict Mode is not set for database connection 'default' HINT: MySQL's Strict Mode fixes many data integrity problems in MySQL,...

 
There's no need to repeat yourself…
The error says "Duplicate column name 'user_id'". Do you already have tables in your database?
 
yeah i have it., but i don't whant drop it coz i have inserted informations
 
Does your current database schema match your migrations (or some version of your migrations)?
 
how i can check it? before do python. manage.py migrate i remove all mirgate files and than do python manage.py makemigrations
 
Where did your existing tables come from? Migrations only work from a known state, and by removing all migration files and generating new ones you've gotten out of sync…
 
8:41 PM
i got all tables with inserted data... Just say how i can fix it?
 
Ideally you "fix it" by not getting out of sync to begin with. Database schemas are complicated, and the easiest way to make sure they match up is to build your schema with migrations in the first place. That's why I'm asking if your schema matches up with any existing migrations. Please answer that question.
 
no they are not a mutched
 
Then there's not much that Django can do to help you. I would explore this chapter in the official documentation about working with legacy databases.
 
heh, so if i have mutched, what i can do?
 
If your database matches some previous migration you can use the --fake option to migrate to mark those migrations as applied, then generate new migrations from that point.
 
8:43 PM
hi
for start i whanna say ty for u. for the your fast help for me
 
I'm glad to help. If you have old migrations that match your current database schema it's going to be a lot easier to fix this problem.
 
I'll tell you how it was
we develop an application together with my partner
he works night and I work day
evening I took him dump database
and model
migrated its database to their local machine
but changed little model added a new table
Then I tried to do
python manage.py ,akemigrations
and I got
E:\PhytonProgects\natarelke>python manage.py makemigrations
Migrations for 'ordering':
ordering\migrations\0001_initial.py:
- Create model UserOrder
- Create model UserOrderAddress
- Create model UserOrderItem
ordering\migrations\0002_userorder_user.py:
- Add field user to userorder
Migrations for 'catalog':
catalog\migrations\0001_initial.py:
- Create model Cuisine
- Create model Dish
- Create model FoodTypeMain
- Create model Honor
- Create model PhotoDish
- Create model PhotoRestaurant
- Create model Promocode
but
next step
python manage.py migrate
O errors that I have asked
forgive me for my bad english
 
9:09 PM
What version of Django are you using? Did your friend's database contain a table called django_migrations?
 
1.10
yeap i got it table
wow
1 contenttypes 0001_initial 2017-02-13 22:06:34
2 auth 0001_initial 2017-02-13 22:06:38
3 admin 0001_initial 2017-02-13 22:06:39
4 admin 0002_logentry_remove_auto_add 2017-02-13 22:06:39
5 contenttypes 0002_remove_content_type_name 2017-02-13 22:06:39
6 auth 0002_alter_permission_name_max_length 2017-02-13 22:06:40
7 auth 0003_alter_user_email_max_length 2017-02-13 22:06:40
8 auth 0004_alter_user_username_opts 2017-02-13 22:06:41
9 auth 0005_alter_user_last_login_null 2017-02-13 22:06:41
10 auth 0006_require_contenttypes_0002 2017-02-13 22:06:41
i should clear that table?
this*
should i*
sorry for my English
 
No, I don't think so… what does python manage.py showmigrations give?
 
E:\PhytonProgects\natarelke>python manage.py showmigrations
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
auth
[X] 0001_initial
[X] 0002_alter_permission_name_max_length
[X] 0003_alter_user_email_max_length
[X] 0004_alter_user_username_opts
[X] 0005_alter_user_last_login_null
[X] 0006_require_contenttypes_0002
[X] 0007_alter_validators_add_error_messages
[X] 0008_alter_user_username_max_length
catalog
[X] 0001_initial
[ ] 0002_auto_20170219_2224
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
 
I think you said you deleted some migration files?
 
each time before you migrate the files I delete the old migration
ш*
i*
 
9:16 PM
That's not a very good idea… you usually need those migration files.
 
,,,,,,,,,,
soory me
 
Can you put them back and run python manage.py showmigrations again?
 
i don't know that
can't i delete it without recovery
 
What version control system are you using? Git? Mercurial? Something else?
 
all mirgations files was aded in ignore list
 
9:18 PM
…okay. This isn't good.
 
Migration files (a) should not be ignored (they're part of your code base) and (b) should not be deleted.
Can you get them from your friend?
 
no he is sleep now
may be i shpould remove
all
and create it ?
tables?
again
 
You will probably have to leave him a message asking for those files, then. Please read the full documentation about Django's migrations before doing much more… You are doing lots of risky things.
 
kk
will do that
so
i think it all
I want to thank you sincerely for your help and your time
 
9:23 PM
Good luck! Sorry I couldn't solve the problem.
 
ty!
bb
u are the best!
 

last day (14 days later) »