I added two new columns to my User model, and I want to migrate the changes. I wrote down exact notes for myself because I have done this before and it worked:
flask shell
from files import db
from files.models import User
Then, I run it and get:
flask db migrate -m "Message"
^
SyntaxError: invalid syntax
I updated Flask-Migrate and everything.
i had same problem and i recognized that i was using "flask shell" and when i changed to terminal i solved my problem
Related
I've created a basic Django website, and I can't create a new app by using commands such as "python manage.py startapp appname" or "admin-py startapp appname".
I'm learning it through a YouTube tutorial, and the author creates the app that way. Once he has typed this command, the appname appears in PyCharm, but in my case, it doesn't.
Neither python manage.py startapp appname nor admin-py startapp appname seem to work.
I know my answer to your question is too late,
however, in case somebody searched about the same problem and found your question
here is the answe,
just put the appname between "" like in the following line :
python manage.py startapp "appname"
also sometimes you have to type python3 or based on the version of python yoy are having, instead of only python :
python3 manage.py startapp "appname"
I renamed some field in my model, and ran
python manage.py makemigration # successful
python manage.py migrate
On the second command I get
NotSupportedError: Renaming the 'my_model'.''my_column' while in a transaction is not supported on SQLite because it would break referential integrity. Try adding atomic = False to the Migration class
However, I don't see which transaction it means. There is no python or sqlite process that is running at the time I get that error. Is some lock left in sqlite or django file? And how do I fix that??
Go to the app folder in which you have renamed some field in the model.
when you have ran this command
python manage.py makemigration.
This in the app folder inside migration folder would have made a migration file (last file, eg: 000_initial).
Open that file inside that Migration Class would be written in the beginning of that class add this.
atomic = False
It will look something like this
class Migration(migrations.Migration):
atomic = False
That will help you run command error free:
python manage.py migrate
For more Reference check: https://docs.djangoproject.com/en/2.1/howto/writing-migrations/
I upload my first Django-project into DigitalOcean. After command python manage.py loaddata initial_data.json, I have received this message:
django.db.utils.IntegrityError: Problem installing fixture
'/webapps/django_shop/shop/initial_data.json': Could not load
contenttypes.ContentType(pk=3): duplicate key value violates unique
constraint "django_content_type_app_label_76bd3d3b_uniq" DETAIL: Key
(app_label, model)=(auth, permission) already exists.
How can I fix it?
I had the same problem and I solved this way
DB with data to export from
python manage.py dumpdata --exclude auth.permission --exclude contenttypes > db.json
New DB to import to
python manage.py flush
// Important! Disable all signals on models pre_save and post_save
python manage.py loaddata db.json
// Do not forget to enable all signals that you disabled
It looks like you've generated fixtures that include Django's default data set, i.e. the built-in entries that are inserted normally as part of the first migrate run for some of Django's plumbing data types.
You should review your fixture process, because content type entries will be created automatically when your (and Django's) apps' migrations are run, so they should not be present in fixtures. It's possible there are other tables that will have this same problem, so now would be a good time to make sure you're not including any other data that would result in this situation.
I'm trying to load fixture:
python manage.py loaddata stock/fixtures/initial_data.json
But error occurred without traceback (I don't know which model is the problem):
ValueError: Problem installing fixture 'stock/fixtures/initial_data.json': The database backend does not accept 0 as a value for AutoField.
How get the traceback?
There's a --traceback option.
python manage.py loaddata stock/fixtures/initial_data.json --traceback
This isn't mentioned in the loaddata docs, it's part of the default command options.
I want to generate a basic DB schema for my django project to display all my Apps with Models and Model Fields with boundary conditions etc. Is there already any DB schema generator for django in python? Or otherwise how should i go about doing it.
If your talking about needing to see the SQL schema, run ./manage.py sqlall <appname>
If you want a visualisation of the schema you can get django-extensions and run ./manage.py graph_models -a -g -o my_project.png. This will produce a pretty schema graph for you, but generally omits border conditions. you may want to check the options to add more data. http://readthedocs.org/docs/django-extensions/en/latest/graph_models.html
manage.py sql <appname appname ...> (docs)
Using Your DB
As mentioned in the tutorial, you can use your database's command line client to get the schema.
Example using sqlite:
python manage.py dbshell
> .schema
You may need to install sqlite3 for this to work.
Using Django
You used to be able to use python manage.py sql ..., but it has been deprecated in 1.9 in favor of migrations. You can check out the initial migration scripts using:
python manage.py sqlmigrate myapp 0001_initial
(From Answer: Equivalent of sqlall in Django 1.9?)