I have made changes to my model.py in Django and now I want to syncronize these changes. It's fine to delete the tables and re-create them. However, nothing seems to work. I am using sqlite3:
syncdb: only works first time, not with changes
"python manage.py sql my_site", followed by syncdb: I thought this would 'redo' it all, but the table still only has the old columns (or so I assume as I get an error when I try to access the table using my model).
Then I figure that I can access the database directly and delete the tables that way. However, I don't know how to get "in" to the DB where I can execute commands. Typing sqlite3 from the command prompt is not recognized. I also tried "python manage.py sql my_site", but I again get the message that sqlite3 is not recognized.
Suggestions?
First you have to install the command line tool for sqlite. On Ubuntu/Debian, you can simply do
sudo apt-get install sqlite3
On windows, you can download it from here: http://www.sqlite.org/download.html. Look for the one that looks like sqlite-shell-win32-xxx.zip.
Use it like this:
> sqlite3 /path/to/your/database
;show some help
.help
; list all databases
.databases
; clear the contents of a table
DELETE FROM <tablename>;
See also the command line reference: http://www.sqlite.org/sqlite.html
and the sqlite SQL reference: http://www.sqlite.org/lang.html.
Using the "ALTER TABLE" sql command, you can also add columns without deleting the entire contents of the table. To do this, compare the output of .schema in sqlite3, and the output of manage.py sql my_site to find out which columns you need to add.
An example:
ALTER TABLE "buildreport_series" ADD COLUMN "parameters" text
Use Django's built in database management tool:
python manage.py dbshell
And issue the required sql commands. The sql command will only print to stdout what the required sql is to create the current tables (as defined by the current models).
Related
Sample database was created but got a glitch while creating and now iam not able to see the tables. How to deleted or drop the db and create a new sample db.
You can drop and recreate the sample database on demand.
To do this, you can use a command line.
On Microsoft-Windows, start > run > db2cwadmin.bat > db2 drop database sample
On Linux bash shell , sudo to the instance-owner (for example su - db2inst1 ) and then run db2 drop database sample
You can recreate the sample database by running the db2sampl command in the same window as the one you used for dropping the database.
You can also give options , additional parameters, to the db2sampl command line to choose a different database-name or other characteristics. Refer to the documentation for details.
=> db2 drop database sample
This command is used to drop the database sample. But few things should be taken care of.
We cannot drop active database or a connected database.
db2 => list active databases // This command will show if sample is active(connected) or not.
If it is active use disconnect sample command and try drop command again.
I'm new to altibase hdb. I was installed altibase hdb with the instructions from here:
http://support.altibase.com/manual/en/631b/html/Installation/index.html
after using the links guides I was able to start the server well but I could not create the database via the recommended command:
CREATE DATABASE mydb INITSIZE=10M NOARCHIVELOG CHARACTER SET KSC5601 NATIONAL CHARACTER SET UTF16;
after some manipulation I found out that the datafiles and anchorlog files were exist here:
$ALTIBASE_HOME\Altibase\altibase-HDB-server-6.3.1\logs
$ALTIBASE_HOME\Altibase\altibase-HDB-server-6.3.1\dbs
So I cleaned them and now I can use the command above to create the database. but if I just rename the databasename to forexample mydbb instead of mydb the command does not work and get me the following error:
Invalid Database Name. Check The Properties and retry.
So what's problem with the database name? what's the difference between mydb and mydbb????
Keep in mind that this same issue should occur even if you install ALTIBASE HDB on Linux.
If you are going to change the database name using the "CREATE DATABASE" command, you must also change the DB_NAME property in your $ALTIBASE_HOME/conf/altibase.properties file to match.
Once you do so, the command you specified should work fine.
I'm trying to drop my database and create a new one through the command line.
I login using psql postgres and then do a \list, see a list of the two databases i created which i now want to delete. so i tried using a DROP DATABASE databasename;
I don't see any error while executing that statement but when i try to \list again to see if that DB are deleted, i still see that that the DB exists. Can someone please tell me why this could happen? and how to surely delete those DB.
There are a couple caveats to DROP DATABASE:
It can only be executed by the database owner.
It cannot be executed while you or anyone else are connected to the target database.
I generally use the dropdb command-line tool to do this, since it's a wrapper around DROP DATABASE which doesn't require you to explicitly connect first. It still has the caveat that there can't be any users currently connected to the database, but it's generally quicker/easier to use.
I would recommend you try issuing a command like this:
dropdb -h <host> -U <user> -p <port> <name of db to drop>
Similarly, you can use the createdb command-line tool to create a database.
More info on DROP DATABASE: http://www.postgresql.org/docs/current/static/sql-dropdatabase.html
Edit:
Also, it is worth looking in the Postgres log (likely in /var/log/postgresql by default) to see if perhaps there is anything in there that wasn't surfaced in the results.
I'm am trying to use mysqldump to export a database which needs to be imported using a different database name. Looking at the SQL generated by mysqldump, it appears that triggers are the only object names which are fully-qualified with the source database name thus foiling my needs. Is there anyway to direct mysqldump to not fully-qualify any object names including triggers?
I had the same problem and I found the solution. I was using MySQL Workbench to design my database and I've created some triggers there. All of them used the syntax CREATE TRIGGER trigger_name except for one: CREATE TRIGGER dbname.trigger_name (it was just my mistake). Mysqldump output included all triggers in the same way: only one had database name.
Mysqldump uses your original CREATE TRIGGER instructions which you can see via SHOW CREATE TRIGGER. If you have a trigger defined with a database name, simply replace it (drop and create) with a one without dbname.
Most probably you add the database name when you create the trigger. Try updating your trigger without the database name in it.
Not an ideal solution but pumping the output through the following has gotten rid of the database name on the triggers for me.
mysqldump ... opts ... | sed -e 's/DEFINER[ ]*=[ ]*[^*]*\*/\*/'
I have approximately 100 SQL views that are a variation of this:
select * from RTC.dbo.MyTable
...now I find I need to change the name of the RTC table to something else. Rather than edit one view at a time, is there a way to script out all their drop/create statements to a text file so that I can do a global replacement?
In SSMS right click the database, go to Tasks and select there 'Generate Scripts...'. Select 'Views', select the views you want exported, export.
I'd use PowerShell. If you're not using SQL 2008 Client Tools, install them. Then get the PowerShell client, add the registered snapins (plenty of information out there on how to do that), and then use the directory structure to get to the folder representing your Views.
Then script them using something like:
Get-ChildItems | % {$_.Script()}
Use ScriptOptions to tell it to use an Alter script.
And replace "RTC." with the new database name... and run them using sqlcmd.
PowerShell actually becomes a really nice deployment option too.