Admin previliges for python, django , sqlite - python

I am new to python and begginer.
Is it necessary to have admin permissions for installing and working with Python , Django , Sqlite.. I have got all the softwares installed bt dont think i have admin previliges . While i am using command
syncdb
I am getting the result as 0 fixtures. But i am not able to create db with the above piece of code.

Being admin or not has no effect at syncdb stage.
Is your DB already there? if yes, then changes in django models doesn't support migrations out of the box. So for example, if you have created DB and then changed your models.pyrunning syncdb now will not change your model.
There is a pluggable app for Django that does exactly that though, and it works great. It's called South.

Related

Django migrations not applying after moving from test PC to production server/DB

I am unable to run the inital migrations in my django project on my production server.
I started working on my Django app on my computer with a sqlite db. I was able to run the initial migrations (auth, admin, etc.) and they created tables in my sqlite db with no problem. I was also able to get tables created for the models in my app.
Today I moved the same django project to my webfaction server via git and I am unable to get my MySQL db populated with tables at all. As soon as I created the db, I ran migrate but it said there were no migrations to apply. I tried deleting the migrations folder in my app, but that didn't help at all, probably because there is no django_migrations table to compare any migrations against.
It seems as if the initial migrations are stored where django is installed. This is not part of my git repo, so anything there that might indicate whether the migrations have been made wouldn't be pulled over.
I tried running python manage.py migrate admin
And the same thing with auth, but it did't work
I'm not really sure what the proper way is to go about getting these initial migrations to run again so that I have the proper auth and admin tables in my db. Any help would be appreciated.
This is Django 2.1.7 and Python 3.5
Thanks, Yongjin and Nagesh. By asking me to post my DB settings, you made me realize that I hadn't changed the name of the DB from the project I copied the settings from. Much appreciated!

Installing django-userena: userena.compat.SiteProfileNotAvailable when trying to create accounts app

Running Django 1.9 I'm trying to follow the install instructions for django-userena, to add it to an existing django project.
When I try to create the Accounts app:
python manage.py startapp accounts
I get this error:
userena.compat.SiteProfileNotAvailable
Other questions indicate that I need to set AUTH_PROFILE_MODULE, as directed in the installation instructions. However, these assume I already have an Accounts app created, within which I've created a Profile model.
So I seem like I'm stuck in a circular dependancy where I can't create the Accounts app without a Profile model, but I can't create the Profile model without the Accounts app!
Also, from the instructions, it doesn't appear the AUTH_PROFILE_MODULE should be required yet at this step, in order to create the Accounts app.
How do I solve this?
Make sure to that userena and the other apps are not yet installed, since
manage.py startapp accounts is the first step in the installation instructions.

Change the order in which Django migrate app during testing

I am using the custom user model which inherits from the AbstractBaseUser class. When I try to migrate after makemigrations command
django.db.utils.ProgrammingError: relation "custom_user_users" does not exist
This is happening since Django is trying to migrate other apps first which depends upon the custom user model. Even I tried to changing the order of the app which contains the custom user model in INSTALLED_APP but no luck.
I know I can force fully migrate custom_user model first then let Django migrate all other models. This solves the problem but during running test it runs the migration in order which Django decides.
How can I alter the order in which apps are migrated during test ? Any other way to solve this dependency problem ?
I am using Django 1.8
Put your your apps before Django apps in INSTALLED_APP in settings.py file
https://pypi.python.org/pypi/django-test-without-migrations adds a --nomigrations flag to manage.py test. Works like a charm.

Django manage.py syncdb doing nothing when used with sqlite3

I'm not sure if this is an issue specific to sqlite databases but after adding some properties I executed syncdb successfully but still the the columns were not added to the database and when I try the access the model in admin I get no such column error.
Why is this happening and how do I overcome this issue?
Details: Django 1.3, Python 2.6, OSX 10.6, PyCharm.
sync db doesn't make integrate schema changes once the tables are created. You have to delete the database manually and do syncdb again. See the boxed information in this link
http://docs.djangoproject.com/en/dev/ref/django-admin/#syncdb
As always, syncdb does not migrate the existing schema.
I think one can find solution here: A nice blog to start with Django:
Getting Started with Django REST Framework (DRF) and AngularJS :
http://engineroom.trackmaven.com/blog/getting-started-drf-angularjs-part-1/

django syncdb and an updated model

I have recently updated my model, added a BooleanField to it however when I do python manage.py syncdb, it doesn't add the new field to the database for the model. How can I fix this ?
From Django 1.7 onwards
Django has built in support for migrations - take a look at the documentation.
For Django 1.6 and earlier
Django doesn't support migrations out of the box. There is a pluggable app for Django that does exactly that though, and it works great. It's called South.
Django currently does not do this automatically. Your options are:
Drop the table from the database, then recreate it in new form using syncdb.
Print out SQL for the database using python manage.py sql (appname), find the added line for the field and add it manually using alter table SQL command. (This will also allow you to choose values of the field for your current records.)
Use South (per Dominic's answer).
Follow these steps:
Export your data to a fixture using the dumpdata management command
Drop the table
Run syncdb
Reload your data from the fixture using the loaddata management command
As suggested in top answer, I tried using South, and after an hour of frustration with obscure migration errors decided to go with Django Evolution instead.
I think it's easier to get started with than South, and it worked perfectly the first time I typed ./manage.py evolve --hint --execute, so I'm happy with it.
Havent used django in a while, but i seem to remember that syncdb does perform alter commands on db tables. you have to drop the table then run again and it will create again.
edit: sorry does NOT perform alter.
In django 1.6
At first we have run - python manage.py sql <app name>
Then we have to run - python manage.py syncdb
If you run Django with Apache and MySQL, restart apache after making migration with makemigrations.

Categories