#help
64 messages · Page 1 of 1 (latest)
Hi. You'll find people are more willing to help if you provide some details about your problem. A good starting point is answering what are you trying to do, what you expect to happen and what actually happened. If your answers are something like "Login to the site. To be logged in. It doesn't work", you're not providing enough detail. If you have an error, include the full error message and the traceback. For a more thorough discussion on how to ask good technical questions see:
https://www.freecodecamp.org/news/how-to-ask-good-technical-questions/
I'm writing the 'python' command manage.py dumpdata product.base > db.json'
the database has a description that stores Russian sentences, and already in json they are strangely encoded in 'фш эрїєщ'
try python -Xutf8 manage.py dumpdata product.base > db.json
Also are you sure you just not looking at the result with wrong encoding?
dont work
when I upload this json file to the database, this nonsense stays there
╨┐╨╕╨┤╨╛╤А
first check if the dump seems okay
how?
open the json file?
[{"model": "appueu.basedatel", "pk": 1, "fields": {"name": "pizdec", "description": "╨┐╨╕╨┤╨╛╤А", "value": 2, "type": 1}}]
still the same after you dump like this?
yes
but in database it looks as its supposed to be?
yes
hmm then I'm not sure, probably an encoding/decoding issue but not sure how to resolve
sadly
What DB are you using?
Also, maybe consider not using dump? fixtures can be problematic anyway.
I need dump to restore the database if I want to add a new column to it. Are there any other ways to create a new column in the database?
sqlite3
How?
Wait a minute, there will be a mistake
Traceback (most recent call last):
Exception Type: OperationalError at /admin/appueu/basedatel/1/change/
Exception Value: no such column: appueu_basedatel.coin
please show the whole log and commands you run
PS C:\Users\dimat\Desktop\My Project\Django\testproject> python manage.py makemigrations
Migrations for 'appueu':
appueu\migrations\0001_initial.py
- Create model cotegory
- Create model baton
- Create model basedatel
PS C:\Users\dimat\Desktop\My Project\Django\testproject> python manage.py migrate
Operations to perform:
Apply all migrations: admin, appueu, auth, contenttypes, sessions, users
Running migrations:
No migrations to apply.
this?
interesting, could you also run showmigrations command as show output. It's strange it says no migrations to apply
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
appueu
[X] 0001_initial
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
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
users
[X] 0001_initial
No
Your command from above says it creates appueu\migrations\0001_initial.py
But showmigrations marked 0001_initial applied
That's won't happen normally
Data you need to save is withing this app?
yes
Can you for now return your models for that app to state that perfectly matches your database?
migrations - database going out of sync is a major problem
do I make a database before adding a new column?
comment all changes in models that don't match current state of DB
that's why you should always keep migration files under git, never delete migration files that are applied (they can be unapplied first) or manually edit database structure. Unless you 100% sure in what are you doing ofc
okay, so how do I add a new column to the database?
You need first to return your migration files to be in sync with DB
otherwise problems will only get worse
I've already done it.
So you have your appueu\migrations\0001_initial.py match exactly your tables?
yes
and showmigrations lists it's as applied?
admin
[X] 0001_initial
[X] 0002_logentry_remove_auto_add
[X] 0003_logentry_add_action_flag_choices
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
[X] 0009_alter_user_last_name_max_length
[X] 0010_alter_group_name_max_length
[X] 0011_update_proxy_permissions
[X] 0012_alter_user_first_name_max_length
contenttypes
[X] 0001_initial
[X] 0002_remove_content_type_name
sessions
[X] 0001_initial
users
[X] 0001_initial
I created the modules, registered the migration command and created a database, it works.
I'm not following...
Again deleting any files in migrations/ is very dangerous
but any model change is just
- changing models.py
- makemigrations
- migrate
If this gives error, you have a problem that must be solved first, not worked around
I have a database. There is data in it. In case I need to add a new column, I do not know how to do it. All I know is that you can delete and recreate the database and all the data will be deleted
you should read migrations https://docs.djangoproject.com/en/4.2/topics/migrations/
Again ^
Every change to DB can (and must, usually) be done with migrations