django fabric syncdb - django

How would you run this django command to syncdb with fabric automatically.
python manage.py syncdb --settings="app.settings.test"
if tried to do run, it gets stuck at the "Do you want to create superuser account", can it passed as yes and login information with it.
run('python manage.py syncdb --settings="app.settings.%s"' % name, pty=True)

Add --noinput to the arguments to keep django-admin from prompting:
python manage.py syncdb --settings="app.settings.%s" --noinput
If you have specific credentials that you'd like to preload always, I suspect the simplest way to achieve that would be to create a data dump of the user database from a machine with (just!) the admin account loaded, and then to load that in after syncdb. Alternatively, you could simply leave out the admin account and add it later with manage.py createsuperuser when and if you need to have it.

Related

Not getting prompt to set up superuser on Django's auth system?

I'm following a tutorial that uses Django's authentication system to log in users and when the sqlite3 db is first connected to django and the command python manage.py syncdb (tutorial is from before syncdb was deprecated) is run, I don't get this same message in the command line:
You just installed Django's auth system, which means you don't have any superusers defined. Would you like to create one now?
I instead ran
python manage.py makemigrations
python manage.py migrate
and this seemed to have set up the tables
but then when I run:
select * from auth_user;
nothing is returned to me in the command line.
How can I setup a superuser from command line and get encrypted password, etc?

How to remove all data about users from database from heroku server?

I created many test accounts in my heroku server. Now they all have empty columns, and therefore do not work. And now I want to remove all data about existing users/accounts, including superuser, then recreate. How I can do this?
You can go to your terminal, where you have executed the command 'python manage.py runserver' and execute the command - 'python manange.py shell', then your shell will start.
Then execute the command:-
step-1: from django.contrib.auth.models import User
step-2: User.objects.all().delete() # this will delete all the user from your table
step-3: exit() # exit from the shell
step-4: python manage.py createsuperuser # for creating the superuser
This is totally in server side.
Go to your heroku database and reset database from the setting.
after that.
$ heroku run python manage.py makemigrations
$ heroku run python manage.py migrate
Create New Admin ( can be any or the same your existing)
All done, 100% that works for me.

How to use django migrate without confirmation

I am using django 1.8.
When using Django's manage.py migrate command, user confirmation is needed when a model as been deleted. The --noinput parameter can avoid user confirmation, but then migration does not remove models.
How can I use manage.py migrate in a script, and remove old models?
And, I know, it can be dangerous.
This is incorrect - --noinput still runs all migrations, including those which remove models.

Reset Django registration models?

I am trying to implement django registration-redux 1.2. I installed the application and added to it settings.py of my project. I ran manage.py syncdb as well as makemigrations/migrate. Typing these commands again and I get no changes detected. However it seems like the tables are not getting created. When I try to register I get the following error:
ProgrammingError at /main/register/ (1146, "Table 'la_test_serve.registration_registrationprofile' doesn't exist")
Is there a way to reset the project/app so that these tables get created?
Thanks,
Robert
Try to run schemamigration for your registration apps
python manage.py schemamigration registration --initial
after that run migrate
python manage.py migrate registration
Remove the app from your "INSTALLED APPS" setting. Then run manage.py makemigrations and manage.py migrate. Reinstall the app.
Note: If you didn't add 'registration' (yes, simply 'registration') to your "INSTALLED APPS", it won't work.
I found this error occurred when I was reinstalling django-registration-redux.
Either way, check that you have deleted not only the table for registration in the database but also ensure that in the migrations table delete the corresponding row, in this case 'registration'.

After south migration failed on sqlite, I switched to MYSQL

So I am a newbie to Django and I had added a field to a model.py and that created issues in Django.
I learned I needed a migration tool, and used south. Turns out south has issues with sqlite. So I configured Django settings for MYSQL. I can add data to the DB (MYSQL)
I deleted the db.sqlite3 file , but it comes back after ever syncdb.
When I run syncdb it says:
Syncing...
Creating tables ...
Installing custom SQL ...
Installing indexes ...
Installed 0 object(s) from 0 fixture(s)
Synced:
> django.contrib.admin
> django.contrib.auth
> django.contrib.contenttypes
> django.contrib.sessions
> django.contrib.messages
> django.contrib.staticfiles
> south
Not synced (use migrations):
- accounts
(use ./manage.py migrate to migrate these)
So my questions are:
1. Changing to MYSQL did not remove the mid migration that south failed on, as I hoped it would. What are my options now in order to deal with this
Do I even have to do anything, or can I keep working on my app or is this mid migration something to address? I ask because the new MYSQL DB seems to have the new field I added, which was why I wanted to migrate in the first place. So you can see my confusion...my migration broke, but now with MYSQL, the fields are fine, but Django still thinks im in the middle of a migration. Why is this and what is the recommendations?
thanks
I have fought many many many (many) times with Databases & Migrations & South... I hope this information helps you to fix your issues and save you some hours of hard work
Migrating accounts app
I have a question here, is accounts the name of your app ? Or is it an external app ?
The accounts app seems to be managed by South, that means that It won't be synced with the command python manage.py syncdb, you will need to migrate it by yourself with:
# This command generates the migrations file
python manage.py shchemamigration accounts --initial
# This command use the migrations file and apply the changes to the DB
python manage.py migrate accounts
# --initial is used only in the INITIAL migration
# If you modify the models on the accounts app and want to migrate again
# You will need to
python manage.py shchemamigration accounts --auto
python manage.py migrate accounts
Keep an eye on your migrations
If you check the folder migrations following the standard structure it is yourapp/yourapp/migrations
If you delete your database, remember to delete your migrations files, is better to start over unless you need to save the Database changes
Make sure that your Database and your migrations are synchronized, if they are synchronized add some changes to the database will be easy
Some times, although you're using south, when you do python manage.py syncdb your app will be synced, I will explain which problems can come from here:
Your app models are created in the database with the command python manage.py syncdb
After 1. you do python manage.py schemamigration --initial and it will create the initial migrations
Now, if you try to do python manage.py migrate yourapp it will fail because the tables has already been created, so you need to fake the initial migration with:
python manage.py migrate yourapp --fake
and from here you could use south without problems
How to "restart" the database
This process will empty the database and delete all the migrations, take care if you have some data you want to save
Sometimes you will mess with the migrations, and depending on the issue, it can be faster to drop the database and start the migrations again:
python manage.py dbshell
# Next 3 lines inside the MySQL console
>> drop database yourappdatabase
>> create database yourappdatabase
>> quit
# Delete all the migrations within the migrations folder
rm yourapp/yourapp/migrations/00*
python manage.py syncdb
python manage.py schemamigration yourapp --initial
python manage.py migrate yourapp
How to save informations from the database
Some times when you're starting a new app you will delete/create the database many times, and to avoid typing again and again data on the models, it could be useful to create migrations from some models with:
python manage.py dumpdata yourapp.ModelName > file.json
To reload this data again you just need to:
python manage.py loaddata file.json